View | Details | Raw Unified | Return to bug 55292
Collapse All | Expand All

(-)test-data/spreadsheet/WithTextBox.xlsx (+28 lines)
Line 0 Link Here
1
PK!ŸÇÂFj?[Content_Types].xml ¢( ÌTËnÂ0¼Wê?D¾V‰?JUU8ôql9Ðpã
+±plËk^ß?	P
2
B ÑKÛ»3³¶w†ãu­“%xTÖ䬟õX¦°R™Yξ§é3K0#…¶r¶dãÑýÝpºq€	eÌY‚{á‹
3
j?™u`h§´¾?¦~Æ?(æb|Ðë=ñš&¤¡Á`£á”b¡Cò¾¦å­Yòº
+l¸r&œÓª?”ò¥‘,iË?QfŒÁJ9| Œw24;´y_t4^IH&‡OQ“¾Ö|eýüÇÚyv¤C¥-KU€´Å¢¦ÈÐy+€Pë,ŽY-”Ùé>ƒ‘Ç¡e!M}øLƒ¢ãñF:½àñ{ù•D˜€a£¯\íô³ôbE&?¼ý¹¼Þè/õÍÄ[‡ä ίzgMvê|P°7‰®fÛ3’ûœOxÐíÐø›ÙÁÍ£ŸŽ~ÿÿPK!µU0#õL_rels/.rels ¢( Œ’ÏNÃ0ÆïH¼CäûênH¡¥»LH»!TÀ$îµ?£$@÷ö„‚JcÛÑöçÏ?[ÞîæiTb/Nú(A±3b{×jx­ŸV b"giǎaWÝÞl_x¤”›b×û¨²‹‹º”ü#b4Oñìr¥‘0QÊahѓ¨eܔå=†¿P-<ÕÁj{ª>ú<ù²·4Mox/æ}b—NŒ@ž;ËvåCf©ÏÛ¨šBËIƒóœÓÉû"cž&Ú\Oôÿ¶8q"K‰ÐHàó<ߊs@ëë?.Ÿh©ø½Î<⧄áMdøaÁÅT_ÿÿPK!»?DÚðGxl/_rels/workbook.xml.rels ¢( ¼’ÍjÃ0„ï…¼ƒØ{¼¶Ó–"çR
4
¹–ô„½þ!¶$´Û¿}…nÁ½„\£E3«Ùí¿†^}PàÎY
+Y’‚"[ºª³?†·ãËú	‹±•é?%
+#1ì‹ÕÝî•z#ñ·?g],khEü‘˖Éódã¤va0ehЛòdÂ<M1üõ€âÌS*
+áPm@G“ÿ÷vuݕôìÊ÷?¬\ˆÀONÜI45¡!Ñ0_1N“M‰/Ãä7†É—`²ÃdK0ׄaûسù?~ôRüý5ã%¶—~Ó'‰Ó9¯Ïê_|ÿÿPK!WÜêbrxl/workbook.xmlŒRËNÃ0¼#ñ–ïԉû®šTB€è!QÚ³‰7?Uǎl‡´Ï&QK8í®w2žg¹:–š|‚óʚ„ƃˆ0™•Êìú¾yº›Qâƒ0Rhk ¡'ðt•ÞÞ,ë֟Ð"„jÁ˜Ï
5
(…Ø
6
nrëJpt{æ+Bú ”šñ(š°R(C{†…û‡Ís•ÁƒÍêLèIhP¾/TåiºÌ•†mªz%ê>jJ´ðáQª2¡cm?\]Ý×Jãv>Œ†”¥“¯ŽHÈE­Ãí?Ù1/>â|Ò"Û(¶
7
ÿýQ;’ãNi›„Žfíé<ŧ¦[í”EBùt:GQýÙ3¨}??ž!éٗ ÞÓUb:{omª1>U[×è{·PظµŒ[†_h~…Æþ‚梇Whì/è.&֑£¤Lè³jK'b4žðîvvþ]Ò/ÿÿPK!ûb¥m”§xl/theme/theme1.xmlìYOoÛ6¿Øw tom'¶uŠØ±›­MÄn‡i™–XS¢@ÒI}Úã€Ãºa—»í0l+лtŸ&[‡­úöHJ²ËKÒÖՇD"|ÿßã#uõڃˆ¡C"$åqÛ«]®zˆÄ>Ó8h{w†ýK’
8
ÇcÌxLÚޜHïÚÖûï]ś*$A°>–›¸í…J%›•ŠôaËË<!1ÌM¸ˆ°‚WTÆ݈UÖªÕf%Â4öPŒ# {{2¡>ACMÒÛʈ÷¼ÆJꟉ?&Mœ;žÖ4BÎe—	tˆYÛ>c~4$”‡–
9
&Ú^Õü¼ÊÖÕ
10
ÞL1µbma]ßüÒué‚ñtÍðÁ(gZë×[WvrúÀÔ2®×ëu{µœž`ßM­,EšõþF­“Ñ,€ìã2ínµQ­»øýõ%™[?N§ÑJe±D
+È>֗ðÕf}{ÍÁ?Å7–ðõÎv·ÛtðdñÍ%|ÿJ«Ywñ2O—ÐÚ¡ý~J=‡L8Û-…o|£šÂ(ˆ†<º4‹	?ÕªX‹ð}.úÐ@†?‘š'd‚}ˆâ.ŽF‚bÍo\˜±C¾\Ò¼?ôMTÛû0Á?z¯žÿêùSôêù“ã‡ÏŽþtüèÑñÃ--gá.Žƒâ—ß~öç×£?ž~óòñåxYÄÿúÃ'¿üüy92h!ы/Ÿüöìɋ¯>ýý»Ç%ðm?GEø?FD¢[äðt3†q%'#q¾ÃSg?v	éž
11
à­9fe¸q?wW@ñ(^ŸÝwd„b¦h	çaä÷8g.J
+pCó*Xx8‹ƒræbVÄ`|XÆ»‹cǵ½YU3JÇöÝ?8bî3+?˜(¤çø”?íîQêØu?ú‚K>QèELKM2¤#'?‹vi~™—é®vl³wu8+Óz‡ºHHÌJ„æ˜ñ:ž)•‘âˆ
+~«°LÈÁ\øE\O*ðt@G½1‘²lÍmúœ~C½*uû›G.R(:-£ys^Dîði7ÄQR†Ð8,b??SQŒö¹*ƒïq7Cô;øÇ+Ý}—Çݧ‚;4pDZˆž™‰_^'܉ßÁœM01UJºS©#ÿ]Ùfê¶åð®l·½mØÄʒg÷D±^…û–è<‹÷	dÅòõ®B¿«ÐÞ[_¡WåòÅ×åE)†*­Ûk›Î;ZÙxO(c5gä¦4½·„
+h܇A½Î:I~KBxԙ\ °YƒWQBœ@ß^ó4‘@¦¤‰.á¼h†Kik<ôþʞ6úb+‡Äj??íðºÎŽ9#U`δ£uMà¬ÌÖ¯¤DA·×aVÓB?™[͈fŠ¢Ã-WY›ØœËÁä¹j0˜[:ýX¹	Ç~ÍÎ;˜‘±¶»õQæㅋt‘ñ˜¤>Òz/û¨fœ”Åʒ"ZúìxŠÕ
12
ÜZšìp;‹“Šìê+ØeÞ{/e¼ðP;™Ž,.&'‹ÑQÛk5ÖòqÒö&pT†Ç(¯KÝLbÀ}“¯„
+ûS“Ùdù›­L17	jpûaí¾¤°S!Ֆ¡
+
+3•†‹5'+ÿZÌzQ
13
”T£³I±¾Áð¯Ivt]K&â«¢³#Úvö5-¥|¦ˆ„ã#4b3q€Áý:TAŸ1•pãa*‚~?ë9mm3åç4銗bgÇ1KBœ–[?¢Y&[¸)H¹æ­ èV*»Qîüª˜”¿ UŠaü?SEï'p±>ÖðávX`¤3¥íq¡BU(	©ßÐ8˜ÚÑW¼0
+AwÔæ¿ ‡ú¿Í9Kä5œ$Õ
+? °©P²eÉDß)ÄjéÞeI²”?‰¨‚¸2±b?È!aC]›zo÷P¡nªIZîdü¹ïi?ÝäóÍ©dùÞksàŸî|l2ƒRn6
+Mfÿ\ļ=Xìªv½Yží½EEôĢͪgYÌ
14
[A+Mû×áœ[­­XK¯52áÀ‹ËÃ`Þ%p‘„ôØÿ¨ð™ýà¡7Ô!?€ÚŠàû…&aQ}É6HH;8‚ÆÉÚ`Ò¤¬iÓÖI[-Û¬/¸ÓÍùž0¶–ì,þ>§±óæÌeçäâE;µ°ck;¶ÒÔàٓ)
15
C“ì cc¾”?fñÑ}pô|6˜1%M0Á§*?¡‡˜<€ä·ÍÒ­¿ÿÿPK!¯ª<½+#xl/worksheets/_rels/sheet1.xml.rels„?Í
16
Â0„ï‚ïönÒz‘¦^Dð*õ–dûƒm²ñ§oo.‚‚àmg—ýf¦Ú?§QÜ)òà?†R Èo×i¸4ÇÕ'tGïHÃLûz¹¨Î4bÊOÜ?E¦8ÖЧvJ±éiB–>?˗ÖÇ	S–±SÍ;Rë¢Ø¨øɀú‹)NVC<ÙD3‡ìüŸíÛv0tðæ6‘K?,”?øÈÍ2cGIƒ”ᅦRæÈ êJ}U¬_ÿÿPK!~ÁŠå`txl/worksheets/sheet2.xmlŒ’ÁjÃ0†ïƒ½ƒñ½qڭے”A)ëa0ƶ»ã(‰ilÛ]Û·Ÿ’?2è¥7	IŸýrº>™–ý‚ómÆçQÌX…¥¶uÆ¿¿¶³Î|?¶”-ZÈø<_ç÷wéÝÞ7?ÁúŒ7!t‰^5`¤?°K•
17
?‘?RWß9?å0dZ±ˆã'a¤¶|$$îV•V°Au0`ÃqÐÊ@ú}£;?ьºg¤Ûº™BӢЭçʙQÉ®¶èdÑÒÞ§ù£T{H®ðF+‡«NŒB¯w^‰• Rž–š6èmgªŒ¿Î¹ÈÓÁœ
+Gÿ/f½×â¾/ìʌÇ}«¸êÝ^8VB%møÄãèº	tØ%iïWHÊó¼"ï-–—G72H¢v²†wéjm=k¡ºž9s#&Ž(Øõ³Ï„,04SÖÐu?®GœUˆaJzµ—ÿ’ÿÿÿPK!~ÁŠå`txl/worksheets/sheet3.xmlŒ’ÁjÃ0†ïƒ½ƒñ½qڭے”A)ëa0ƶ»ã(‰ilÛ]Û·Ÿ’?2è¥7	IŸýrº>™–ý‚ómÆçQÌX…¥¶uÆ¿¿¶³Î|?¶”-ZÈø<_ç÷wéÝÞ7?ÁúŒ7!t‰^5`¤?°K•
18
?‘?RWß9?å0dZ±ˆã'a¤¶|$$îV•V°Au0`ÃqÐÊ@ú}£;?ьºg¤Ûº™BӢЭçʙQÉ®¶èdÑÒÞ§ù£T{H®ðF+‡«NŒB¯w^‰• Rž–š6èmgªŒ¿Î¹ÈÓÁœ
+Gÿ/f½×â¾/ìʌÇ}«¸êÝ^8VB%møÄãèº	tØ%iïWHÊó¼"ï-–—G72H¢v²†wéjm=k¡ºž9s#&Ž(Øõ³Ï„,04SÖÐu?®GœUˆaJzµ—ÿ’ÿÿÿPK!裌W’Ìxl/worksheets/sheet1.xmlŒ’MoÛ0†ïúÝk9ÝG[#N14(–Àaív—%Ú"‰žÄ4Í¿­ÀE?^z#%êyõ’\ß½/ž!e‡±•«ª–¢AëâÐÊ?O—7RdÒÑj?Zy‚,ï6ŸÖGLû<?`BÌ­‰¦F©lF:W8Aä›SÐÄiTžh[¯®êú›
19
ÚEy&4é#ì{g`‹æ ҒÀkâÿçÑMy¡ó\Ði˜.
+†‰?óŽN*E0Ínˆ˜tçÙ÷Ëê‹6»$ïðÁ™„{ª§Î}ïùVÝ*&mÖÖ±ƒ¹í"AßÊï+©6ëҜ¿ŽùM,Hw?àÁXž‘sï;Äý\¸ã£šq¹Ì8mÈ=Ã=xßÊÝWß¿"À!¨W…·ñ¢öP¦õ+	½>xú?Çà†‘X–IÅwcO[Ȇ»ÏÂÕU¡èV“f…IðS§ÁÅ,<ô¥êZŠtÆÔDŽÓüöš‘aX²‘÷xêê³="-	smÒGÞJ‘Ç–ÓΖ†©×=ÜüÿÿPK!ó6d÷xl/drawings/drawing1.xml¤UÛNã0}_iÿÁò;äҖ–ˆ- ò‚ûnⴎ?µ½½ðõ;cçÒ"±]Ø>¸öØsæxæxrq¹­Ysm*%S?†”p™«¢’Ë”þ|™ŸÌ(1–É‚	%yJwÜÐËìû·‹m¡“?¹Ñ¤I`™Ò•µM&_ñš™SÕp	»¥Ò5³°ÔË Ðlеâ0<L£9+̊s{ãwh‹Ç¾€V³JÒÌ1³uͅø!ó•ÒÞTjUûY®D_xœ:˜<”edz³0ì÷Ð䶵Úd‘7ã´³á~?fñ¤ßs.{hU$›öà½
+]&á¸Gi¹tA²ü0ð8žM‡½!pÎ4¤f¹V)¥Äò­•|…¹‘ëçæ±MM~¿~Ô¤*RS"Y
+u~?óWjK"´<ï?±[0ƒRÐd$K¶¥†\³D•%ÁÃãñt‚´v)EãQ<Ao–@’Ãþh?c0’LgQ8	üÔhco¹ª	NRªyná,aë;c‘	Kº#h6JTżP\X ùµÐdÍDJ…õÜß?’lRz>q4êraäÒÅ8æb¬XÁ=þ$„_K¿íî_!Ûú¤¡?Ý	ŽpB>ñ
20
¹	=‡\/xxe?Gx›0.pô—wèYÂ¥?éÛº 7/KÈì'ý{'_ÉÁ¿®¤Ò-ÿƒ¯]
+J¾K…OæuVìrÿ OhRö†R((T.ª†xÜoïmÍ(Þ¯ßLsJ´×
21
ªéb®€«Õ^~ÂØgè´Ø`(?/ab	?Pø#­¬‚aCäòäö
22
âh:‚*ãî^UaіÉ)m>ߗ I(>@¢¯Íî*É	tœãf=™CF=íÿâ†Èª“çǜ9ZËY0á½@ã8–”!@ ;OH[Å#éø5$w<7dt@ž?,™fO_Ô	ªäƒ¸r§×s»ÇáÔâ¾e¢âÒÞ0Ë°'¸7tøt6üfgÿÿPK!ýïú\nY
+xl/styles.xml¤”M?Ú0†ï•ú,ßÁ!…- $+i¥mU	*õê$N°Ö‘íl¡Uÿ{ÇùÄ¡•–?'Ï̼'z<I?ޘ±\«Ï¦FLåºàªŠñ÷C:YbdUZ±Ÿ™Å?ÉǑugÁöGƄ²1>:W¯	±ù‘Ij§ºf
23
vJm$u°4±µa´°þ%)HDR®pGXËü ’š×¦žäZÖÔñŒîÎ-#™¯Ÿ+¥
+͔zšÍi>°ÛÅ^òÜh«K7ÑeÉsv_劬?’¨ÔÊY”ëF9Ð
24
Ð>ÃúUéŸ*õ[ÞÙE%‘ý…ިϓ$ʵÐ9P
25
k=ŠJÖEl©à™á>¬¤’‹sç½£³?“ZóNâëè^âBŒU…¾p$¨ã˜Q),PoÎ5¤Wp?¦?ûGteèy.®^ mÂ$Ê´)`p.z®$¬tP¨áÕÑ??®á?ÓÎ?ÊITpZiE˜¤ƒŒ´“3!ö~¸~”7ìS‰T#S鞋Øzé͎×-<ÿšÖ±ß?E§ò–Ä«²oŠÓ#Þ1þêoƒ€Éé(k¸p\ÝÛö?Yœ.þœŸìnw?”(XIáãfŒ/öVðF†cÔ7þ¦]‹ˆñÅ~ñ'5{ð9ÚQ…äÒ4[?µ¾·vzM•Å8Mø¥é‰F·ßºswñÞM®€dHÂNîÅÂ,Ã5†Çø÷Óæój÷”†“e°YNæŸØb²Zlv“Å|»ÙíÒUÛ?W·úwºýö$ÜâµpóM¯l¯çþâ‹ñÕ¢Óªm	ʆƆ&ˆ¿‰É_ÿÿPK!òˆ¢!>WdocProps/core.xml ¢( Œ’QKÃ0…ßÿCÉ{›¦Å©¡í@eO'ßBr·›4$ÑnþzÓv«•ùàã½çä»ç^RÌ÷ªŽ>Á:Ùè‘$EhÞ©·%zY-â9Ï´`u£¡Dph^]^ÜPÞXx²?ë%¸(?´£Ü”h罡;¾Å\:ˆ›Æ*æCi·Ø0þζ€³4?až	æ‰èˆ|Dš[÷Á1Ô @{‡IBð?׃UîϽ2q*é&ìtŒ;e>ˆ£{ïählÛ6ió>FÈOðëòñ¹_5–º»T‚Sn?ùÆV‚}xRw·«™óËpæ?qw,çí@éC(QˆA‡Ð'e?ß?¬¨ÊR’Çéuœå+’QrK¯foÝÔ_ï»XCCgÿ›˜e4%â	Pøì+TßÿÿPK!Ï@ü´‹4docProps/app.xml ¢( œ“OOã0Åï+ñ"ß©Ó­V•c„ø#¬¶Rœ?3i,\;òQ»Ÿ~'‰JS.Üfæ==ý<¶Õån볺
26
1?ä"ƒ`cé¦?ë»ó_"C2¡4>(ÄP\ê³j™b‰`ÆQ5)ÑÖ°58a9°RÅ´5ÄmÚÈXUÎÂM´o[$gyþSŽ ”Pž7ï?bH\´ôÝÐ2ڎŸÖû†?µºjï¬!>¥þílŠ+Ênw¼’cQ1Ý
27
ì[r´×¹’ãV­¬ñpÍÁº2AÉã@݃閶4.¡V--Z°S†î/¯m&²ƒÐá¢5ə@ŒÕن¦¯}ƒ”ôsL¯X*Ɇaؗcï¸vzÞ¸85v§ˆkGðOµ4‰>!ž?‰{†?wÀYu|Ó1ß;i/;–Òñ©úE1ߢ^ñ±YÇCpØøéP­j“ äK:èÇ?ºçe'߅\×&l <xþº÷ñ4|=½˜äóœ¯~4SòøÜõ?ÿÿPK-!ŸÇÂFj?[Content_Types].xmlPK-!µU0#õL£_rels/.relsPK-!»?DÚðGÉxl/_rels/workbook.xml.relsPK-!WÜêbrùxl/workbook.xmlPK-!ûb¥m”§ˆ
28
xl/theme/theme1.xmlPK-!¯ª<½+#Mxl/worksheets/_rels/sheet1.xml.relsPK-!~ÁŠå`tKxl/worksheets/sheet2.xmlPK-!~ÁŠå`táxl/worksheets/sheet3.xmlPK-!裌W’Ìwxl/worksheets/sheet1.xmlPK-!ó6d÷?xl/drawings/drawing1.xmlPK-!ýïú\nY
+wxl/styles.xmlPK-!òˆ¢!>WdocProps/core.xmlPK-!Ï@ü´‹4…docProps/app.xmlPK
+
+aF"
(-)src/ooxml/java/org/apache/poi/xssf/usermodel/TextDirection.java (+48 lines)
Line 0 Link Here
1
/*
2
 *  ====================================================================
3
 *    Licensed to the Apache Software Foundation (ASF) under one or more
4
 *    contributor license agreements.  See the NOTICE file distributed with
5
 *    this work for additional information regarding copyright ownership.
6
 *    The ASF licenses this file to You under the Apache License, Version 2.0
7
 *    (the "License"); you may not use this file except in compliance with
8
 *    the License.  You may obtain a copy of the License at
9
 *
10
 *        http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 *    Unless required by applicable law or agreed to in writing, software
13
 *    distributed under the License is distributed on an "AS IS" BASIS,
14
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 *    See the License for the specific language governing permissions and
16
 *    limitations under the License.
17
 * ====================================================================
18
 */
19
package org.apache.poi.xssf.usermodel;
20
21
/**
22
 * Vertical Text Types
23
 */
24
public enum TextDirection {
25
    /**
26
     * Horizontal text. This should be default.
27
     */
28
    HORIZONTAL,
29
    /**
30
     * Vertical orientation.
31
     * (each line is 90 degrees rotated clockwise, so it goes
32
     * from top to bottom; each next line is to the left from
33
     * the previous one).
34
     */
35
    VERTICAL,
36
    /**
37
     * Vertical orientation.
38
     * (each line is 270 degrees rotated clockwise, so it goes
39
     * from bottom to top; each next line is to the right from
40
     * the previous one).
41
     */
42
    VERTICAL_270,
43
    /**
44
     * Determines if all of the text is vertical
45
     * ("one letter on top of another").
46
     */
47
    STACKED;
48
}
(-)src/ooxml/java/org/apache/poi/xssf/usermodel/TextCap.java (+30 lines)
Line 0 Link Here
1
/*
2
 *  ====================================================================
3
 *    Licensed to the Apache Software Foundation (ASF) under one or more
4
 *    contributor license agreements.  See the NOTICE file distributed with
5
 *    this work for additional information regarding copyright ownership.
6
 *    The ASF licenses this file to You under the Apache License, Version 2.0
7
 *    (the "License"); you may not use this file except in compliance with
8
 *    the License.  You may obtain a copy of the License at
9
 *
10
 *        http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 *    Unless required by applicable law or agreed to in writing, software
13
 *    distributed under the License is distributed on an "AS IS" BASIS,
14
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 *    See the License for the specific language governing permissions and
16
 *    limitations under the License.
17
 * ====================================================================
18
 */
19
20
package org.apache.poi.xssf.usermodel;
21
22
/**
23
 * Text Capitalization that is to be applied to the text run. This is a render-only
24
 * modification and does not affect the actual characters stored in the text run.
25
 */
26
public enum TextCap {
27
    NONE,
28
    SMALL,
29
    ALL
30
}
(-)src/ooxml/java/org/apache/poi/xssf/usermodel/TextAlign.java (+48 lines)
Line 0 Link Here
1
/*
2
 *  ====================================================================
3
 *    Licensed to the Apache Software Foundation (ASF) under one or more
4
 *    contributor license agreements.  See the NOTICE file distributed with
5
 *    this work for additional information regarding copyright ownership.
6
 *    The ASF licenses this file to You under the Apache License, Version 2.0
7
 *    (the "License"); you may not use this file except in compliance with
8
 *    the License.  You may obtain a copy of the License at
9
 *
10
 *        http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 *    Unless required by applicable law or agreed to in writing, software
13
 *    distributed under the License is distributed on an "AS IS" BASIS,
14
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 *    See the License for the specific language governing permissions and
16
 *    limitations under the License.
17
 * ====================================================================
18
 */
19
package org.apache.poi.xssf.usermodel;
20
21
/**
22
 * Specified a list of text alignment types
23
 */
24
public enum TextAlign {
25
    /**
26
     * Align text to the left margin.
27
     */
28
    LEFT,
29
    /**
30
     * Align text in the center.
31
     */
32
    CENTER,
33
34
    /**
35
     * Align text to the right margin.
36
     */
37
    RIGHT,
38
39
    /**
40
     * Align text so that it is justified across the whole line. It
41
     * is smart in the sense that it will not justify sentences
42
     * which are short
43
     */
44
    JUSTIFY,
45
    JUSTIFY_LOW,
46
    DIST,
47
    THAI_DIST
48
}
(-)src/ooxml/java/org/apache/poi/xssf/usermodel/TextAutofit.java (+57 lines)
Line 0 Link Here
1
/*
2
 *  ====================================================================
3
 *    Licensed to the Apache Software Foundation (ASF) under one or more
4
 *    contributor license agreements.  See the NOTICE file distributed with
5
 *    this work for additional information regarding copyright ownership.
6
 *    The ASF licenses this file to You under the Apache License, Version 2.0
7
 *    (the "License"); you may not use this file except in compliance with
8
 *    the License.  You may obtain a copy of the License at
9
 *
10
 *        http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 *    Unless required by applicable law or agreed to in writing, software
13
 *    distributed under the License is distributed on an "AS IS" BASIS,
14
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 *    See the License for the specific language governing permissions and
16
 *    limitations under the License.
17
 * ====================================================================
18
 */
19
package org.apache.poi.xssf.usermodel;
20
21
/**
22
 * Specifies a list of auto-fit types.
23
 * <p>
24
 * Autofit specofies that a shape should be auto-fit to fully contain the text described within it.
25
 * Auto-fitting is when text within a shape is scaled in order to contain all the text inside
26
 * </p>
27
 */
28
public enum TextAutofit {
29
    /**
30
     * Specifies that text within the text body should not be auto-fit to the bounding box.
31
     * Auto-fitting is when text within a text box is scaled in order to remain inside
32
     * the text box.
33
     */
34
    NONE,
35
    /**
36
     * Specifies that text within the text body should be normally auto-fit to the bounding box.
37
     * Autofitting is when text within a text box is scaled in order to remain inside the text box.
38
     *
39
     * <p>
40
     * <em>Example:</em> Consider the situation where a user is building a diagram and needs
41
     * to have the text for each shape that they are using stay within the bounds of the shape.
42
     * An easy way this might be done is by using NORMAL autofit
43
     * </p>
44
     */
45
    NORMAL,
46
    /**
47
     * Specifies that a shape should be auto-fit to fully contain the text described within it.
48
     * Auto-fitting is when text within a shape is scaled in order to contain all the text inside.
49
     *
50
     * <p>
51
     * <em>Example:</em> Consider the situation where a user is building a diagram and needs to have
52
     * the text for each shape that they are using stay within the bounds of the shape.
53
     * An easy way this might be done is by using SHAPE autofit
54
     * </p>
55
     */
56
    SHAPE
57
}
(-)src/ooxml/java/org/apache/poi/xssf/usermodel/TextFontAlign.java (+47 lines)
Line 0 Link Here
1
/*
2
 *  ====================================================================
3
 *    Licensed to the Apache Software Foundation (ASF) under one or more
4
 *    contributor license agreements.  See the NOTICE file distributed with
5
 *    this work for additional information regarding copyright ownership.
6
 *    The ASF licenses this file to You under the Apache License, Version 2.0
7
 *    (the "License"); you may not use this file except in compliance with
8
 *    the License.  You may obtain a copy of the License at
9
 *
10
 *        http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 *    Unless required by applicable law or agreed to in writing, software
13
 *    distributed under the License is distributed on an "AS IS" BASIS,
14
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 *    See the License for the specific language governing permissions and
16
 *    limitations under the License.
17
 * ====================================================================
18
 */
19
package org.apache.poi.xssf.usermodel;
20
21
/**
22
 * Specified a list of text font alignment types
23
 */
24
public enum TextFontAlign {
25
	/**
26
	 * Automatic alignment
27
	 */
28
	AUTO,
29
    /**
30
     * Align text to the top.
31
     */
32
    TOP,
33
    /**
34
     * Align text in the center.
35
     */
36
    CENTER,
37
38
    /**
39
     * Align text to the baseline.
40
     */
41
    BASELINE,
42
43
    /**
44
     * Align text to the bottom.
45
     */
46
    BOTTOM
47
}
(-)src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSimpleShape.java (-41 / +463 lines)
Lines 17-22 Link Here
17
17
18
package org.apache.poi.xssf.usermodel;
18
package org.apache.poi.xssf.usermodel;
19
19
20
import java.util.ArrayList;
21
import java.util.Iterator;
22
import java.util.List;
23
20
import org.apache.poi.hssf.util.HSSFColor;
24
import org.apache.poi.hssf.util.HSSFColor;
21
import org.openxmlformats.schemas.drawingml.x2006.main.*;
25
import org.openxmlformats.schemas.drawingml.x2006.main.*;
22
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShape;
26
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShape;
Lines 24-38 Link Here
24
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRElt;
28
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRElt;
25
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRPrElt;
29
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRPrElt;
26
import org.apache.poi.util.Internal;
30
import org.apache.poi.util.Internal;
31
import org.apache.poi.util.Units;
32
import org.apache.poi.ss.usermodel.VerticalAlignment;
27
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STUnderlineValues;
33
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STUnderlineValues;
28
34
29
/**
35
/**
30
 * Represents a shape with a predefined geometry in a SpreadsheetML drawing.
36
 * Represents a shape with a predefined geometry in a SpreadsheetML drawing.
31
 * Possible shape types are defined in {@link org.apache.poi.ss.usermodel.ShapeTypes}
37
 * Possible shape types are defined in {@link org.apache.poi.ss.usermodel.ShapeTypes}
32
 *
33
 * @author Yegor Kozlov
34
 */
38
 */
35
public class XSSFSimpleShape extends XSSFShape { // TODO - instantiable superclass
39
public class XSSFSimpleShape extends XSSFShape implements Iterable<XSSFTextParagraph> { // TODO - instantiable superclass
40
	/**
41
	 * List of the paragraphs that make up the text in this shape
42
	 */
43
    private final List<XSSFTextParagraph> _paragraphs;
36
    /**
44
    /**
37
     * A default instance of CTShape used for creating new shapes.
45
     * A default instance of CTShape used for creating new shapes.
38
     */
46
     */
Lines 46-51 Link Here
46
    protected XSSFSimpleShape(XSSFDrawing drawing, CTShape ctShape) {
54
    protected XSSFSimpleShape(XSSFDrawing drawing, CTShape ctShape) {
47
        this.drawing = drawing;
55
        this.drawing = drawing;
48
        this.ctShape = ctShape;
56
        this.ctShape = ctShape;
57
        
58
        _paragraphs = new ArrayList<XSSFTextParagraph>();
59
        
60
        // initialize any existing paragraphs - this will be the default body paragraph in a new shape, 
61
        // or existing paragraphs that have been loaded from the file
62
        CTTextBody body = ctShape.getTxBody();
63
        for(int i = 0; i < body.sizeOfPArray(); i++) {
64
            _paragraphs.add(new XSSFTextParagraph(body.getPArray(i), ctShape));        	
65
        }
49
    }
66
    }
50
67
51
    /**
68
    /**
Lines 74-107 Link Here
74
            geom.setPrst(STShapeType.RECT);
91
            geom.setPrst(STShapeType.RECT);
75
            geom.addNewAvLst();
92
            geom.addNewAvLst();
76
93
77
            CTShapeStyle style = shape.addNewStyle();
78
            CTSchemeColor scheme = style.addNewLnRef().addNewSchemeClr();
79
            scheme.setVal(STSchemeColorVal.ACCENT_1);
80
            scheme.addNewShade().setVal(50000);
81
            style.getLnRef().setIdx(2);
82
83
            CTStyleMatrixReference fillref = style.addNewFillRef();
84
            fillref.setIdx(1);
85
            fillref.addNewSchemeClr().setVal(STSchemeColorVal.ACCENT_1);
86
87
            CTStyleMatrixReference effectRef = style.addNewEffectRef();
88
            effectRef.setIdx(0);
89
            effectRef.addNewSchemeClr().setVal(STSchemeColorVal.ACCENT_1);
90
91
            CTFontReference fontRef = style.addNewFontRef();
92
            fontRef.setIdx(STFontCollectionIndex.MINOR);
93
            fontRef.addNewSchemeClr().setVal(STSchemeColorVal.LT_1);
94
95
            CTTextBody body = shape.addNewTxBody();
94
            CTTextBody body = shape.addNewTxBody();
96
            CTTextBodyProperties bodypr = body.addNewBodyPr();
95
            CTTextBodyProperties bodypr = body.addNewBodyPr();
97
            bodypr.setAnchor(STTextAnchoringType.CTR);
96
            bodypr.setAnchor(STTextAnchoringType.T);
98
            bodypr.setRtlCol(false);
97
            bodypr.setRtlCol(false);
99
            CTTextParagraph p = body.addNewP();
98
            CTTextParagraph p = body.addNewP();
100
            p.addNewPPr().setAlgn(STTextAlignType.CTR);
99
            p.addNewPPr().setAlgn(STTextAlignType.L);
101
            CTTextCharacterProperties endPr = p.addNewEndParaRPr();
100
            CTTextCharacterProperties endPr = p.addNewEndParaRPr();
102
            endPr.setLang("en-US");
101
            endPr.setLang("en-US");
103
            endPr.setSz(1100);
102
            endPr.setSz(1100);   
104
103
            CTSolidColorFillProperties scfpr = endPr.addNewSolidFill();
104
            scfpr.addNewSrgbClr().setVal(new byte[] { 0, 0, 0 });
105
                        
105
            body.addNewLstStyle();
106
            body.addNewLstStyle();
106
107
107
            prototype = shape;
108
            prototype = shape;
Lines 114-143 Link Here
114
        return ctShape;
115
        return ctShape;
115
    }
116
    }
116
117
118
119
    public Iterator<XSSFTextParagraph> iterator(){
120
        return _paragraphs.iterator();
121
    }
122
117
    /**
123
    /**
118
     * Gets the shape type, one of the constants defined in {@link org.apache.poi.ss.usermodel.ShapeTypes}.
124
     * Returns the text from all paragraphs in the shape. Paragraphs are separated by new lines.
119
     *
125
     * 
120
     * @return the shape type
126
     * @return  text contained within this shape or empty string
121
     * @see org.apache.poi.ss.usermodel.ShapeTypes
122
     */
127
     */
123
    public int getShapeType() {
128
    public String getText() {
124
        return ctShape.getSpPr().getPrstGeom().getPrst().intValue();
129
        StringBuilder out = new StringBuilder();
130
        for (XSSFTextParagraph p : _paragraphs) {
131
            if (out.length() > 0) out.append('\n');
132
            out.append(p.getText());
133
        }
134
        return out.toString();
125
    }
135
    }
126
136
127
    /**
137
    /**
128
     * Sets the shape types.
138
     * Clear all text from this shape
129
     *
130
     * @param type the shape type, one of the constants defined in {@link org.apache.poi.ss.usermodel.ShapeTypes}.
131
     * @see org.apache.poi.ss.usermodel.ShapeTypes
132
     */
139
     */
133
    public void setShapeType(int type) {
140
    public void clearText(){
134
        ctShape.getSpPr().getPrstGeom().setPrst(STShapeType.Enum.forInt(type));
141
        _paragraphs.clear();
142
        CTTextBody txBody = ctShape.getTxBody();
143
        txBody.setPArray(null); // remove any existing paragraphs
135
    }
144
    }
145
    
146
    /**
147
     * Set a single paragraph of text on the shape. Note this will replace all existing paragraphs created on the shape.
148
     * @param text	string representing the paragraph text
149
     */
150
    public void setText(String text){
151
        clearText();
136
152
137
    protected CTShapeProperties getShapeProperties(){
153
        addNewTextParagraph().addNewTextRun().setText(text);
138
        return ctShape.getSpPr();
139
    }
154
    }
140
155
156
    /**
157
     * Set a single paragraph of text on the shape. Note this will replace all existing paragraphs created on the shape.
158
     * @param str	rich text string representing the paragraph text
159
     */
141
    public void setText(XSSFRichTextString str){
160
    public void setText(XSSFRichTextString str){
142
161
143
        XSSFWorkbook wb = (XSSFWorkbook)getDrawing().getParent().getParent();
162
        XSSFWorkbook wb = (XSSFWorkbook)getDrawing().getParent().getParent();
Lines 166-177 Link Here
166
                r.setT(lt.getT());
185
                r.setT(lt.getT());
167
            }
186
            }
168
        }
187
        }
188
        
189
        clearText();                
169
        ctShape.getTxBody().setPArray(new CTTextParagraph[]{p});
190
        ctShape.getTxBody().setPArray(new CTTextParagraph[]{p});
191
        _paragraphs.add(new XSSFTextParagraph(ctShape.getTxBody().getPArray(0), ctShape));
192
    }    
193
    
194
    /**
195
     * Returns a collection of the XSSFTextParagraphs that are attached to this shape
196
     * 
197
     * @return text paragraphs in this shape
198
     */
199
    public List<XSSFTextParagraph> getTextParagraphs() {
200
        return _paragraphs;
201
    }
202
203
    /**
204
     * Add a new paragraph run to this shape
205
     *
206
     * @return created paragraph run
207
     */
208
    public XSSFTextParagraph addNewTextParagraph() {
209
        CTTextBody txBody = ctShape.getTxBody();
210
        CTTextParagraph p = txBody.addNewP();
211
        XSSFTextParagraph paragraph = new XSSFTextParagraph(p, ctShape);
212
        _paragraphs.add(paragraph);
213
        return paragraph;
214
    }    
215
216
    /**
217
     * Add a new paragraph run to this shape, set to the provided rich text string 
218
     *
219
     * @return created paragraph run
220
     */
221
    public XSSFTextParagraph addNewTextParagraph(XSSFRichTextString str) {
222
        CTTextBody txBody = ctShape.getTxBody();
223
        CTTextParagraph p = txBody.addNewP();
224
       
225
        if(str.numFormattingRuns() == 0){
226
            CTRegularTextRun r = p.addNewR();
227
            CTTextCharacterProperties rPr = r.addNewRPr();
228
            rPr.setLang("en-US");
229
            rPr.setSz(1100);
230
            r.setT(str.getString());
231
232
        } else {
233
            for (int i = 0; i < str.getCTRst().sizeOfRArray(); i++) {
234
                CTRElt lt = str.getCTRst().getRArray(i);
235
                CTRPrElt ltPr = lt.getRPr();
236
                if(ltPr == null) ltPr = lt.addNewRPr();
237
238
                CTRegularTextRun r = p.addNewR();
239
                CTTextCharacterProperties rPr = r.addNewRPr();
240
                rPr.setLang("en-US");
241
242
                applyAttributes(ltPr, rPr);
243
244
                r.setT(lt.getT());
245
            }
246
        }
247
        
248
        // Note: the XSSFTextParagraph constructor will create its required XSSFTextRuns from the provided CTTextParagraph
249
        XSSFTextParagraph paragraph = new XSSFTextParagraph(p, ctShape);
250
        _paragraphs.add(paragraph);
251
        
252
        return paragraph;
253
    }
254
255
    /**
256
     * Sets the type of horizontal overflow for the text.
257
     *
258
     * @param overflow - the type of horizontal overflow.
259
     * A <code>null</code> values unsets this property.
260
     */
261
    public void setTextHorizontalOverflow(TextHorizontalOverflow overflow){
262
        CTTextBodyProperties bodyPr = ctShape.getTxBody().getBodyPr();
263
        if (bodyPr != null) {
264
             if(anchor == null) {
265
                if(bodyPr.isSetHorzOverflow()) bodyPr.unsetHorzOverflow();
266
            } else {
267
                bodyPr.setHorzOverflow(STTextHorzOverflowType.Enum.forInt(overflow.ordinal() + 1));
268
            }
269
        }
270
    }
271
272
    /**
273
     * Returns the type of horizontal overflow for the text.
274
     *
275
     * @return the type of horizontal overflow
276
     */
277
    public TextHorizontalOverflow getTextHorizontalOverflow(){
278
    	CTTextBodyProperties bodyPr = ctShape.getTxBody().getBodyPr();
279
    	if(bodyPr != null) {
280
    		if(bodyPr.isSetHorzOverflow()){
281
    			return TextHorizontalOverflow.values()[bodyPr.getVertOverflow().intValue() - 1];
282
    		}    			
283
    	}
284
    	return TextHorizontalOverflow.OVERFLOW;
285
    }    
286
    
287
    /**
288
     * Sets the type of vertical overflow for the text.
289
     *
290
     * @param overflow - the type of vertical overflow.
291
     * A <code>null</code> values unsets this property.
292
     */
293
    public void setTextVerticalOverflow(TextVerticalOverflow overflow){
294
        CTTextBodyProperties bodyPr = ctShape.getTxBody().getBodyPr();
295
        if (bodyPr != null) {
296
             if(anchor == null) {
297
                if(bodyPr.isSetVertOverflow()) bodyPr.unsetVertOverflow();
298
            } else {
299
                bodyPr.setVertOverflow(STTextVertOverflowType.Enum.forInt(overflow.ordinal() + 1));
300
            }
301
        }
302
    }
303
304
    /**
305
     * Returns the type of vertical overflow for the text.
306
     *
307
     * @return the type of vertical overflow
308
     */
309
    public TextVerticalOverflow getTextVerticalOverflow(){
310
    	CTTextBodyProperties bodyPr = ctShape.getTxBody().getBodyPr();
311
    	if(bodyPr != null) {
312
    		if(bodyPr.isSetVertOverflow()){
313
    			return TextVerticalOverflow.values()[bodyPr.getVertOverflow().intValue() - 1];
314
    		}    			
315
    	}
316
    	return TextVerticalOverflow.OVERFLOW;
317
    }   
318
    
319
    /**
320
     * Sets the type of vertical alignment for the text within the shape.
321
     *
322
     * @param anchor - the type of alignment.
323
     * A <code>null</code> values unsets this property.
324
     */
325
    public void setVerticalAlignment(VerticalAlignment anchor){
326
        CTTextBodyProperties bodyPr = ctShape.getTxBody().getBodyPr();
327
        if (bodyPr != null) {
328
             if(anchor == null) {
329
                if(bodyPr.isSetAnchor()) bodyPr.unsetAnchor();
330
            } else {
331
                bodyPr.setAnchor(STTextAnchoringType.Enum.forInt(anchor.ordinal() + 1));
332
            }
333
        }
334
    }
335
336
    /**
337
     * Returns the type of vertical alignment for the text within the shape.
338
     *
339
     * @return the type of vertical alignment
340
     */
341
    public VerticalAlignment getVerticalAlignment(){
342
    	CTTextBodyProperties bodyPr = ctShape.getTxBody().getBodyPr();
343
    	if(bodyPr != null) {
344
    		if(bodyPr.isSetAnchor()){
345
    			return VerticalAlignment.values()[bodyPr.getAnchor().intValue() - 1];
346
    		}    			
347
    	}
348
    	return VerticalAlignment.TOP;
349
    }
350
351
    /**
352
     * Sets the vertical orientation of the text
353
     * 
354
     * @param orientation vertical orientation of the text
355
     * A <code>null</code> values unsets this property.
356
     */
357
    public void setTextDirection(TextDirection orientation){
358
        CTTextBodyProperties bodyPr = ctShape.getTxBody().getBodyPr();
359
        if (bodyPr != null) {
360
            if(orientation == null) {
361
                if(bodyPr.isSetVert()) bodyPr.unsetVert();
362
            } else {
363
                bodyPr.setVert(STTextVerticalType.Enum.forInt(orientation.ordinal() + 1));
364
            }
365
        }
366
    }
367
368
    /**
369
     * Gets the vertical orientation of the text
370
     * 
371
     * @return vertical orientation of the text
372
     */
373
    public TextDirection getTextDirection(){
374
        CTTextBodyProperties bodyPr = ctShape.getTxBody().getBodyPr();
375
        if (bodyPr != null) {
376
            STTextVerticalType.Enum val = bodyPr.getVert();
377
            if(val != null){
378
                return TextDirection.values()[val.intValue() - 1];
379
            }
380
        }
381
        return TextDirection.HORIZONTAL;
382
    }
383
384
385
    /**
386
     * Returns the distance (in points) between the bottom of the text frame
387
     * and the bottom of the inscribed rectangle of the shape that contains the text.
388
     *
389
     * @return the bottom inset in points
390
     */
391
    public double getBottomInset(){
392
        CTTextBodyProperties bodyPr = ctShape.getTxBody().getBodyPr();
393
        if (bodyPr != null) {
394
        	if(bodyPr.isSetBIns()){
395
        		return Units.toPoints(bodyPr.getBIns());
396
        	}
397
        }
398
        // If this attribute is omitted, then a value of 0.05 inches is implied
399
        return 3.6;	
400
    }
401
402
    /**
403
     *  Returns the distance (in points) between the left edge of the text frame
404
     *  and the left edge of the inscribed rectangle of the shape that contains
405
     *  the text.
406
     *
407
     * @return the left inset in points
408
     */
409
    public double getLeftInset(){
410
        CTTextBodyProperties bodyPr = ctShape.getTxBody().getBodyPr();
411
        if (bodyPr != null) {
412
        	if(bodyPr.isSetLIns()){
413
        		return Units.toPoints(bodyPr.getLIns());
414
        	}
415
        }
416
        // If this attribute is omitted, then a value of 0.05 inches is implied
417
        return 3.6;
418
    }
419
420
    /**
421
     *  Returns the distance (in points) between the right edge of the
422
     *  text frame and the right edge of the inscribed rectangle of the shape
423
     *  that contains the text.
424
     *
425
     * @return the right inset in points
426
     */
427
    public double getRightInset(){
428
        CTTextBodyProperties bodyPr = ctShape.getTxBody().getBodyPr();
429
        if (bodyPr != null) {
430
        	if(bodyPr.isSetRIns()){
431
        		return Units.toPoints(bodyPr.getRIns());
432
        	}
433
        }
434
        // If this attribute is omitted, then a value of 0.05 inches is implied
435
        return 3.6;
436
    }
437
438
    /**
439
     *  Returns the distance (in points) between the top of the text frame
440
     *  and the top of the inscribed rectangle of the shape that contains the text.
441
     *
442
     * @return the top inset in points
443
     */
444
    public double getTopInset(){
445
        CTTextBodyProperties bodyPr = ctShape.getTxBody().getBodyPr();
446
        if (bodyPr != null) {
447
        	if(bodyPr.isSetTIns()){
448
        		return Units.toPoints(bodyPr.getTIns());
449
        	}
450
        }
451
        // If this attribute is omitted, then a value of 0.05 inches is implied
452
        return 3.6;    	
453
    }
454
455
    /**
456
     * Sets the bottom inset.
457
     * @see #getBottomInset()
458
     *
459
     * @param margin    the bottom margin
460
     */
461
    public void setBottomInset(double margin){
462
        CTTextBodyProperties bodyPr = ctShape.getTxBody().getBodyPr();
463
        if (bodyPr != null) {
464
            if(margin == -1) bodyPr.unsetBIns();
465
            else bodyPr.setBIns(Units.toEMU(margin));
466
        }
467
    }
468
469
    /**
470
     * Sets the left inset.
471
     * @see #getLeftInset()
472
     *
473
     * @param margin    the left margin
474
     */
475
    public void setLeftInset(double margin){
476
        CTTextBodyProperties bodyPr = ctShape.getTxBody().getBodyPr();
477
        if (bodyPr != null) {
478
            if(margin == -1) bodyPr.unsetLIns();
479
            else bodyPr.setLIns(Units.toEMU(margin));
480
        }
481
    }
482
483
    /**
484
     * Sets the right inset.
485
     * @see #getRightInset()
486
     *
487
     * @param margin    the right margin
488
     */
489
    public void setRightInset(double margin){
490
        CTTextBodyProperties bodyPr = ctShape.getTxBody().getBodyPr();
491
        if (bodyPr != null) {
492
            if(margin == -1) bodyPr.unsetRIns();
493
            else bodyPr.setRIns(Units.toEMU(margin));
494
        }
495
    }
496
497
    /**
498
     * Sets the top inset.
499
     * @see #getTopInset()
500
     *
501
     * @param margin    the top margin
502
     */
503
    public void setTopInset(double margin){
504
        CTTextBodyProperties bodyPr = ctShape.getTxBody().getBodyPr();
505
        if (bodyPr != null) {
506
            if(margin == -1) bodyPr.unsetTIns();
507
            else bodyPr.setTIns(Units.toEMU(margin));
508
        }
509
    }
510
511
512
    /**
513
     * @return whether to wrap words within the bounding rectangle
514
     */
515
    public boolean getWordWrap(){
516
    	CTTextBodyProperties bodyPr = ctShape.getTxBody().getBodyPr();
517
        if (bodyPr != null) {
518
        	if(bodyPr.isSetWrap()){
519
        		return bodyPr.getWrap() == STTextWrappingType.SQUARE;
520
        	}
521
        }
522
        return true;
523
    }
524
525
    /**
526
     *
527
     * @param wrap  whether to wrap words within the bounding rectangle
528
     */
529
    public void setWordWrap(boolean wrap){
530
        CTTextBodyProperties bodyPr = ctShape.getTxBody().getBodyPr();
531
        if (bodyPr != null) {
532
            bodyPr.setWrap(wrap ? STTextWrappingType.SQUARE : STTextWrappingType.NONE);
533
        }
534
    }
535
536
    /**
537
     *
538
     * Specifies that a shape should be auto-fit to fully contain the text described within it.
539
     * Auto-fitting is when text within a shape is scaled in order to contain all the text inside
540
     *
541
     * @param value type of autofit
542
     */
543
    public void setTextAutofit(TextAutofit value){
544
        CTTextBodyProperties bodyPr = ctShape.getTxBody().getBodyPr();
545
        if (bodyPr != null) {
546
            if(bodyPr.isSetSpAutoFit()) bodyPr.unsetSpAutoFit();
547
            if(bodyPr.isSetNoAutofit()) bodyPr.unsetNoAutofit();
548
            if(bodyPr.isSetNormAutofit()) bodyPr.unsetNormAutofit();
549
550
            switch(value){
551
                case NONE: bodyPr.addNewNoAutofit(); break;
552
                case NORMAL: bodyPr.addNewNormAutofit(); break;
553
                case SHAPE: bodyPr.addNewSpAutoFit(); break;
554
            }
555
        }
556
    }
170
557
558
    /**
559
     *
560
     * @return type of autofit
561
     */
562
    public TextAutofit getTextAutofit(){
563
        CTTextBodyProperties bodyPr = ctShape.getTxBody().getBodyPr();
564
        if (bodyPr != null) {
565
            if(bodyPr.isSetNoAutofit()) return TextAutofit.NONE;
566
            else if (bodyPr.isSetNormAutofit()) return TextAutofit.NORMAL;
567
            else if (bodyPr.isSetSpAutoFit()) return TextAutofit.SHAPE;
568
        }
569
        return TextAutofit.NORMAL;
570
    }
571
    
572
    /**
573
     * Gets the shape type, one of the constants defined in {@link org.apache.poi.ss.usermodel.ShapeTypes}.
574
     *
575
     * @return the shape type
576
     * @see org.apache.poi.ss.usermodel.ShapeTypes
577
     */
578
    public int getShapeType() {
579
        return ctShape.getSpPr().getPrstGeom().getPrst().intValue();
171
    }
580
    }
172
581
173
    /**
582
    /**
583
     * Sets the shape types.
174
     *
584
     *
585
     * @param type the shape type, one of the constants defined in {@link org.apache.poi.ss.usermodel.ShapeTypes}.
586
     * @see org.apache.poi.ss.usermodel.ShapeTypes
587
     */
588
    public void setShapeType(int type) {
589
        ctShape.getSpPr().getPrstGeom().setPrst(STShapeType.Enum.forInt(type));
590
    }
591
592
    protected CTShapeProperties getShapeProperties(){
593
        return ctShape.getSpPr();
594
    }
595
596
    /**
175
     * org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRPrElt to
597
     * org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRPrElt to
176
     * org.openxmlformats.schemas.drawingml.x2006.main.CTFont adapter
598
     * org.openxmlformats.schemas.drawingml.x2006.main.CTFont adapter
177
     */
599
     */
Lines 186-193 Link Here
186
        }
608
        }
187
        if(pr.sizeOfIArray() > 0) rPr.setI(pr.getIArray(0).getVal());
609
        if(pr.sizeOfIArray() > 0) rPr.setI(pr.getIArray(0).getVal());
188
610
189
        if(pr.sizeOfFamilyArray() > 0) {
611
        if(pr.sizeOfRFontArray() > 0) {
190
            CTTextFont rFont = rPr.addNewLatin();
612
            CTTextFont rFont = rPr.isSetLatin() ? rPr.getLatin() : rPr.addNewLatin();
191
            rFont.setTypeface(pr.getRFontArray(0).getVal());
613
            rFont.setTypeface(pr.getRFontArray(0).getVal());
192
        }
614
        }
193
615
(-)src/ooxml/java/org/apache/poi/xssf/usermodel/TextVerticalOverflow.java (+41 lines)
Line 0 Link Here
1
/*
2
 *  ====================================================================
3
 *    Licensed to the Apache Software Foundation (ASF) under one or more
4
 *    contributor license agreements.  See the NOTICE file distributed with
5
 *    this work for additional information regarding copyright ownership.
6
 *    The ASF licenses this file to You under the Apache License, Version 2.0
7
 *    (the "License"); you may not use this file except in compliance with
8
 *    the License.  You may obtain a copy of the License at
9
 *
10
 *        http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 *    Unless required by applicable law or agreed to in writing, software
13
 *    distributed under the License is distributed on an "AS IS" BASIS,
14
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 *    See the License for the specific language governing permissions and
16
 *    limitations under the License.
17
 * ====================================================================
18
 */
19
package org.apache.poi.xssf.usermodel;
20
21
/**
22
 * Text Vertical Overflow
23
 */
24
public enum TextVerticalOverflow {
25
    /**
26
     * Overflow the text and pay no attention to top and bottom barriers.
27
     */
28
    OVERFLOW,
29
30
    /**
31
     * Pay attention to top and bottom barriers. Use an
32
     * ellipsis to denote that there is text which is not visible.     
33
     */
34
    ELLIPSIS,
35
36
    /**
37
     * Pay attention to top and bottom barriers. Provide no
38
     * indication that there is text which is not visible.
39
     */
40
    CLIP
41
}
(-)src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTextParagraph.java (+483 lines)
Line 0 Link Here
1
/* ====================================================================
2
   Licensed to the Apache Software Foundation (ASF) under one or more
3
   contributor license agreements.  See the NOTICE file distributed with
4
   this work for additional information regarding copyright ownership.
5
   The ASF licenses this file to You under the Apache License, Version 2.0
6
   (the "License"); you may not use this file except in compliance with
7
   the License.  You may obtain a copy of the License at
8
9
       http://www.apache.org/licenses/LICENSE-2.0
10
11
   Unless required by applicable law or agreed to in writing, software
12
   distributed under the License is distributed on an "AS IS" BASIS,
13
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
   See the License for the specific language governing permissions and
15
   limitations under the License.
16
==================================================================== */
17
package org.apache.poi.xssf.usermodel;
18
19
20
import org.apache.poi.util.Internal;
21
import org.apache.poi.util.Units;
22
import org.apache.xmlbeans.XmlObject;
23
import org.openxmlformats.schemas.drawingml.x2006.main.*;
24
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShape;
25
26
27
import java.util.ArrayList;
28
import java.util.Iterator;
29
import java.util.List;
30
31
/**
32
 * Represents a paragraph of text within the containing text body.
33
 * The paragraph is the highest level text separation mechanism.
34
 */
35
public class XSSFTextParagraph implements Iterable<XSSFTextRun>{
36
    private final CTTextParagraph _p;
37
    private final CTShape _shape;
38
    private final List<XSSFTextRun> _runs;
39
40
    XSSFTextParagraph(CTTextParagraph p, CTShape ctShape){
41
        _p = p;
42
        _shape = ctShape;
43
        _runs = new ArrayList<XSSFTextRun>();
44
45
        for(XmlObject ch : _p.selectPath("*")){
46
            if(ch instanceof CTRegularTextRun){
47
                CTRegularTextRun r = (CTRegularTextRun)ch;
48
                _runs.add(new XSSFTextRun(r, this));
49
            } else if (ch instanceof CTTextLineBreak){
50
                CTTextLineBreak br = (CTTextLineBreak)ch;
51
                CTRegularTextRun r = CTRegularTextRun.Factory.newInstance();
52
                r.setRPr(br.getRPr());
53
                r.setT("\n");
54
                _runs.add(new XSSFTextRun(r, this));
55
            } else if (ch instanceof CTTextField){
56
                CTTextField f = (CTTextField)ch;
57
                CTRegularTextRun r = CTRegularTextRun.Factory.newInstance();
58
                r.setRPr(f.getRPr());
59
                r.setT(f.getT());
60
                _runs.add(new XSSFTextRun(r, this));
61
            }
62
        }
63
    }
64
65
    public String getText(){
66
        StringBuilder out = new StringBuilder();
67
        for (XSSFTextRun r : _runs) {
68
            out.append(r.getText());
69
        }
70
        return out.toString();
71
    }
72
73
    @Internal
74
    public CTTextParagraph getXmlObject(){
75
        return _p;
76
    }
77
78
    @Internal
79
    public CTShape getParentShape(){
80
        return _shape;
81
    }
82
83
    public List<XSSFTextRun> getTextRuns(){
84
        return _runs;
85
    }
86
87
    public Iterator<XSSFTextRun> iterator(){
88
        return _runs.iterator();
89
    }
90
91
    /**
92
     * Add a new run of text
93
     *
94
     * @return a new run of text
95
     */
96
    public XSSFTextRun addNewTextRun(){
97
        CTRegularTextRun r = _p.addNewR();
98
        CTTextCharacterProperties rPr = r.addNewRPr();
99
        rPr.setLang("en-US");
100
        XSSFTextRun run = new XSSFTextRun(r, this);
101
        _runs.add(run);
102
        return run;
103
    }
104
105
    /**
106
     * Insert a line break
107
     *
108
     * @return text run representing this line break ('\n')
109
     */
110
    public XSSFTextRun addLineBreak(){
111
        CTTextLineBreak br = _p.addNewBr();
112
        CTTextCharacterProperties brProps = br.addNewRPr();
113
        if(_runs.size() > 0){
114
            // by default line break has the font size of the last text run
115
            CTTextCharacterProperties prevRun = _runs.get(_runs.size() - 1).getRPr();
116
            brProps.set(prevRun);
117
        }
118
        CTRegularTextRun r = CTRegularTextRun.Factory.newInstance();
119
        r.setRPr(brProps);
120
        r.setT("\n");
121
        XSSFTextRun run = new XSSFLineBreak(r, this, brProps);
122
        _runs.add(run);
123
        return run;
124
    }
125
126
    /**
127
     * Returns the alignment that is applied to the paragraph.
128
     *
129
     * If this attribute is omitted, then a value of left is implied.
130
     * @return alignment that is applied to the paragraph
131
     */
132
    public TextAlign getTextAlign(){
133
        CTTextParagraphProperties pr = _p.getPPr();
134
        if(pr != null) {
135
            return pr.isSetAlgn() ? TextAlign.values()[pr.getAlgn().intValue() - 1] : TextAlign.LEFT;    	
136
        }
137
        return TextAlign.LEFT;        
138
    }
139
140
    /**
141
     * Specifies the alignment that is to be applied to the paragraph.
142
     * Possible values for this include left, right, centered, justified and distributed,
143
     * see {@link org.apache.poi.xssf.usermodel.TextAlign}.
144
     *
145
     * @param align text align
146
     */
147
    public void setTextAlign(TextAlign align){
148
        CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr();
149
        if(align == null) {
150
            if(pr.isSetAlgn()) pr.unsetAlgn();
151
        } else {
152
            pr.setAlgn(STTextAlignType.Enum.forInt(align.ordinal() + 1));
153
        }
154
    }    
155
156
    /**
157
     * Returns the font alignment that is applied to the paragraph.
158
     *
159
     * If this attribute is omitted, then a value of baseline is implied.
160
     * @return alignment that is applied to the paragraph
161
     */
162
    public TextFontAlign getTextFontAlign(){
163
        CTTextParagraphProperties pr = _p.getPPr();
164
        if(pr != null) {
165
            return pr.isSetFontAlgn() ? TextFontAlign.values()[pr.getFontAlgn().intValue() - 1] : TextFontAlign.BASELINE;    	
166
        }
167
        return TextFontAlign.BASELINE;
168
    }
169
170
    /**
171
     * Determines where vertically on a line of text the actual words are positioned. This deals
172
     * with vertical placement of the characters with respect to the baselines. For instance
173
     * having text anchored to the top baseline, anchored to the bottom baseline, centered in
174
     * between, etc.
175
     *
176
     * @param align text font align
177
     */
178
    public void setTextFontAlign(TextFontAlign align){
179
        CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr();
180
        if(align == null) {
181
            if(pr.isSetFontAlgn()) pr.unsetFontAlgn();
182
        } else {
183
            pr.setFontAlgn(STTextFontAlignType.Enum.forInt(align.ordinal() + 1));
184
        }
185
    }
186
187
188
189
    /**
190
     * Specifies the indent size that will be applied to the first line of text in the paragraph.
191
     *
192
     * @param value the indent in points. 
193
     */
194
    public void setIndent(double value){
195
        CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr();
196
        if(value == -1) {
197
            if(pr.isSetIndent()) pr.unsetIndent();
198
        } else {
199
            pr.setIndent(Units.toEMU(value));
200
        }
201
    }
202
203
    /**
204
     *
205
     * @return the indent applied to the first line of text in the paragraph.
206
     */
207
    public double getIndent(){
208
        CTTextParagraphProperties pr = _p.getPPr();
209
        if(pr == null) return 0;
210
211
        return Units.toPoints(pr.getIndent());
212
    }
213
214
215
216
    /**
217
     * Specifies the left margin of the paragraph. This is specified in addition to the text body
218
     * inset and applies only to this text paragraph. That is the text body inset and the LeftMargin
219
     * attributes are additive with respect to the text position.
220
     *
221
     * @param value the left margin of the paragraph
222
     */
223
    public void setLeftMargin(double value){
224
        CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr();
225
        if(value == -1) {
226
            if(pr.isSetMarL()) pr.unsetMarL();
227
        } else {
228
            pr.setMarL(Units.toEMU(value));
229
        }
230
231
    }
232
233
    /**
234
     *
235
     * @return the left margin of the paragraph
236
     */
237
    public double getLeftMargin(){
238
        CTTextParagraphProperties pr = _p.getPPr();
239
        if(pr != null && pr.isSetMarL()) {
240
            return Units.toPoints(pr.getMarL());
241
        }    	
242
        return 347663;	// return the default which is 347663   	
243
    }
244
245
    /**
246
     * Specifies the right margin of the paragraph. This is specified in addition to the text body
247
     * inset and applies only to this text paragraph. That is the text body inset and the marR
248
     * attributes are additive with respect to the text position.
249
     *
250
     * @param value the right margin of the paragraph
251
     */
252
    public void setRightMargin(double value){
253
        CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr();
254
        if(value == -1) {
255
            if(pr.isSetMarR()) pr.unsetMarR();
256
        } else {
257
            pr.setMarR(Units.toEMU(value));
258
        }
259
260
    }
261
262
    /**
263
     *
264
     * @return the right margin of the paragraph
265
     */
266
    public double getRightMargin(){
267
        CTTextParagraphProperties pr = _p.getPPr();
268
        if(pr != null && pr.isSetMarR()) {
269
            return Units.toPoints(pr.getMarR());
270
        }    	
271
        return 0;	// return the default which is 0    	
272
    }    
273
274
    /**
275
     * Add a single tab stop to be used on a line of text when there are one or more tab characters
276
     * present within the text. 
277
     * 
278
     * @param value the position of the tab stop relative to the left margin
279
     */
280
    public void addTabStop(double value){
281
        CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr();
282
        CTTextTabStopList tabStops = pr.isSetTabLst() ? pr.getTabLst() : pr.addNewTabLst();
283
        tabStops.addNewTab().setPos(Units.toEMU(value));
284
    }
285
286
    /**
287
     * This element specifies the vertical line spacing that is to be used within a paragraph.
288
     * This may be specified in two different ways, percentage spacing and font point spacing:
289
     * <p>
290
     * If linespacing >= 0, then linespacing is a percentage of normal line height
291
     * If linespacing < 0, the absolute value of linespacing is the spacing in points
292
     * </p>
293
     * Examples:
294
     * <pre><code>
295
     *      // spacing will be 120% of the size of the largest text on each line
296
     *      paragraph.setLineSpacing(120);
297
     *
298
     *      // spacing will be 200% of the size of the largest text on each line
299
     *      paragraph.setLineSpacing(200);
300
     *
301
     *      // spacing will be 48 points
302
     *      paragraph.setLineSpacing(-48.0);
303
     * </code></pre>
304
     * 
305
     * @param linespacing the vertical line spacing
306
     */
307
    public void setLineSpacing(double linespacing){
308
        CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr();
309
        CTTextSpacing spc = CTTextSpacing.Factory.newInstance();
310
        if(linespacing >= 0) spc.addNewSpcPct().setVal((int)(linespacing*1000));
311
        else spc.addNewSpcPts().setVal((int)(-linespacing*100));
312
        pr.setLnSpc(spc);
313
    }
314
315
    /**
316
     * Returns the vertical line spacing that is to be used within a paragraph.
317
     * This may be specified in two different ways, percentage spacing and font point spacing:
318
     * <p>
319
     * If linespacing >= 0, then linespacing is a percentage of normal line height.
320
     * If linespacing < 0, the absolute value of linespacing is the spacing in points
321
     * </p>
322
     *
323
     * @return the vertical line spacing.
324
     */
325
    public double getLineSpacing(){
326
        CTTextParagraphProperties pr = _p.getPPr();
327
        double lnSpc = 100;	// assume 100% default
328
        if(pr != null) {
329
            if(pr.isSetLnSpc()){
330
                CTTextSpacing spc = pr.getLnSpc();
331
332
                if(spc.isSetSpcPct()) 
333
                    lnSpc = spc.getSpcPct().getVal()*0.001;
334
                else if (spc.isSetSpcPts()) 
335
                    lnSpc = -spc.getSpcPts().getVal()*0.01;
336
            }
337
        }
338
339
        if(lnSpc > 0) {
340
            // check if the percentage value is scaled
341
            CTTextNormalAutofit normAutofit = getParentShape().getTxBody().getBodyPr().getNormAutofit();
342
            if(normAutofit != null) {
343
                double scale = 1 - (double)normAutofit.getLnSpcReduction() / 100000;
344
                lnSpc *= scale;
345
            }
346
        }
347
        return lnSpc;
348
    }
349
350
    /**
351
     * Set the amount of vertical white space that will be present before the paragraph.
352
     * This space is specified in either percentage or points:
353
     * <p>
354
     * If spaceBefore >= 0, then space is a percentage of normal line height.
355
     * If spaceBefore < 0, the absolute value of linespacing is the spacing in points
356
     * </p>
357
     * Examples:
358
     * <pre><code>
359
     *      // The paragraph will be formatted to have a spacing before the paragraph text.
360
     *      // The spacing will be 200% of the size of the largest text on each line
361
     *      paragraph.setSpaceBefore(200);
362
     *
363
     *      // The spacing will be a size of 48 points
364
     *      paragraph.setSpaceBefore(-48.0);
365
     * </code></pre>
366
     *
367
     * @param spaceBefore the vertical white space before the paragraph.
368
     */
369
    public void setSpaceBefore(double spaceBefore){
370
        CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr();
371
        CTTextSpacing spc = CTTextSpacing.Factory.newInstance();
372
        if(spaceBefore >= 0) spc.addNewSpcPct().setVal((int)(spaceBefore*1000));
373
        else spc.addNewSpcPts().setVal((int)(-spaceBefore*100));
374
        pr.setSpcBef(spc);
375
    }
376
377
    /**
378
     * The amount of vertical white space before the paragraph
379
     * This may be specified in two different ways, percentage spacing and font point spacing:
380
     * <p>
381
     * If spaceBefore >= 0, then space is a percentage of normal line height.
382
     * If spaceBefore < 0, the absolute value of linespacing is the spacing in points
383
     * </p>
384
     *
385
     * @return the vertical white space before the paragraph
386
     */
387
    public double getSpaceBefore(){
388
        CTTextParagraphProperties pr = _p.getPPr();
389
        if(pr != null) {
390
            if(pr.isSetSpcBef()) {
391
                CTTextSpacing spc = pr.getSpcBef();
392
393
                if(spc.isSetSpcPct()) 
394
                    return spc.getSpcPct().getVal()*0.001;
395
                else if (spc.isSetSpcPts()) 
396
                    return -spc.getSpcPts().getVal()*0.01;    			
397
            }
398
        }
399
        return 0;
400
    }
401
402
    /**
403
     * Set the amount of vertical white space that will be present after the paragraph.
404
     * This space is specified in either percentage or points:
405
     * <p>
406
     * If spaceAfter >= 0, then space is a percentage of normal line height.
407
     * If spaceAfter < 0, the absolute value of linespacing is the spacing in points
408
     * </p>
409
     * Examples:
410
     * <pre><code>
411
     *      // The paragraph will be formatted to have a spacing after the paragraph text.
412
     *      // The spacing will be 200% of the size of the largest text on each line
413
     *      paragraph.setSpaceAfter(200);
414
     *
415
     *      // The spacing will be a size of 48 points
416
     *      paragraph.setSpaceAfter(-48.0);
417
     * </code></pre>
418
     *
419
     * @param spaceAfter the vertical white space after the paragraph.
420
     */
421
    public void setSpaceAfter(double spaceAfter){
422
        CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr();
423
        CTTextSpacing spc = CTTextSpacing.Factory.newInstance();
424
        if(spaceAfter >= 0) spc.addNewSpcPct().setVal((int)(spaceAfter*1000));
425
        else spc.addNewSpcPts().setVal((int)(-spaceAfter*100));
426
        pr.setSpcAft(spc);
427
    }
428
429
    /**
430
     * The amount of vertical white space after the paragraph
431
     * This may be specified in two different ways, percentage spacing and font point spacing:
432
     * <p>
433
     * If spaceBefore >= 0, then space is a percentage of normal line height.
434
     * If spaceBefore < 0, the absolute value of linespacing is the spacing in points
435
     * </p>
436
     *
437
     * @return the vertical white space after the paragraph
438
     */
439
    public double getSpaceAfter(){
440
        CTTextParagraphProperties pr = _p.getPPr();
441
        if(pr != null) {
442
            if(pr.isSetSpcAft()) {
443
                CTTextSpacing spc = pr.getSpcAft();
444
445
                if(spc.isSetSpcPct()) 
446
                    return spc.getSpcPct().getVal()*0.001;
447
                else if (spc.isSetSpcPts()) 
448
                    return -spc.getSpcPts().getVal()*0.01;    			
449
            }
450
        }
451
        return 0;
452
    }
453
454
    /**
455
     * Specifies the particular level text properties that this paragraph will follow.
456
     * The value for this attribute formats the text according to the corresponding level
457
     * paragraph properties defined in the SlideMaster.
458
     *
459
     * @param level the level (0 ... 4)
460
     */
461
    public void setLevel(int level){
462
        CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr();
463
464
        pr.setLvl(level);
465
    }
466
467
    /**
468
     *
469
     * @return the text level of this paragraph (0-based). Default is 0.
470
     */
471
    public int getLevel(){
472
        CTTextParagraphProperties pr = _p.getPPr();
473
        if(pr == null) return 0;
474
475
        return pr.getLvl();
476
477
    }
478
479
    @Override
480
    public String toString(){
481
        return "[" + getClass() + "]" + getText();
482
    }
483
}
(-)src/ooxml/java/org/apache/poi/xssf/usermodel/TextHorizontalOverflow.java (+36 lines)
Line 0 Link Here
1
/*
2
 *  ====================================================================
3
 *    Licensed to the Apache Software Foundation (ASF) under one or more
4
 *    contributor license agreements.  See the NOTICE file distributed with
5
 *    this work for additional information regarding copyright ownership.
6
 *    The ASF licenses this file to You under the Apache License, Version 2.0
7
 *    (the "License"); you may not use this file except in compliance with
8
 *    the License.  You may obtain a copy of the License at
9
 *
10
 *        http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 *    Unless required by applicable law or agreed to in writing, software
13
 *    distributed under the License is distributed on an "AS IS" BASIS,
14
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 *    See the License for the specific language governing permissions and
16
 *    limitations under the License.
17
 * ====================================================================
18
 */
19
package org.apache.poi.xssf.usermodel;
20
21
/**
22
 * Text Horizontal Overflow
23
 */
24
public enum TextHorizontalOverflow {
25
    /**
26
     * When a big character does not fit into a line, allow a
27
     * horizontal overflow.
28
     */
29
    OVERFLOW,
30
31
    /**
32
     * When a big character does not fit into a line, clip it at
33
     * the proper horizontal overflow.
34
     */
35
    CLIP
36
}
(-)src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTextRun.java (+356 lines)
Line 0 Link Here
1
/* ====================================================================
2
   Licensed to the Apache Software Foundation (ASF) under one or more
3
   contributor license agreements.  See the NOTICE file distributed with
4
   this work for additional information regarding copyright ownership.
5
   The ASF licenses this file to You under the Apache License, Version 2.0
6
   (the "License"); you may not use this file except in compliance with
7
   the License.  You may obtain a copy of the License at
8
9
       http://www.apache.org/licenses/LICENSE-2.0
10
11
   Unless required by applicable law or agreed to in writing, software
12
   distributed under the License is distributed on an "AS IS" BASIS,
13
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
   See the License for the specific language governing permissions and
15
   limitations under the License.
16
==================================================================== */
17
package org.apache.poi.xssf.usermodel;
18
19
import org.openxmlformats.schemas.drawingml.x2006.main.CTRegularTextRun;
20
import org.openxmlformats.schemas.drawingml.x2006.main.CTSRgbColor;
21
import org.openxmlformats.schemas.drawingml.x2006.main.CTSolidColorFillProperties;
22
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties;
23
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextFont;
24
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextNormalAutofit;
25
import org.openxmlformats.schemas.drawingml.x2006.main.STTextStrikeType;
26
import org.openxmlformats.schemas.drawingml.x2006.main.STTextUnderlineType;
27
28
import java.awt.Color;
29
30
/**
31
 * Represents a run of text within the containing text body. The run element is the
32
 * lowest level text separation mechanism within a text body.
33
 */
34
public class XSSFTextRun {
35
    private final CTRegularTextRun _r;
36
    private final XSSFTextParagraph _p;
37
38
    XSSFTextRun(CTRegularTextRun r, XSSFTextParagraph p){
39
        _r = r;
40
        _p = p;
41
    }
42
43
    XSSFTextParagraph getParentParagraph(){
44
        return _p;
45
    }
46
47
    public String getText(){
48
        return _r.getT();
49
    }
50
51
    public void setText(String text){
52
        _r.setT(text);
53
    }
54
55
    public CTRegularTextRun getXmlObject(){
56
        return _r;
57
    }
58
59
    public void setFontColor(Color color){
60
        CTTextCharacterProperties rPr = getRPr();
61
        CTSolidColorFillProperties fill = rPr.isSetSolidFill() ? rPr.getSolidFill() : rPr.addNewSolidFill();
62
        CTSRgbColor clr = fill.isSetSrgbClr() ? fill.getSrgbClr() : fill.addNewSrgbClr();
63
        clr.setVal(new byte[]{(byte)color.getRed(), (byte)color.getGreen(), (byte)color.getBlue()});
64
65
        if(fill.isSetHslClr()) fill.unsetHslClr();
66
        if(fill.isSetPrstClr()) fill.unsetPrstClr();
67
        if(fill.isSetSchemeClr()) fill.unsetSchemeClr();
68
        if(fill.isSetScrgbClr()) fill.unsetScrgbClr();
69
        if(fill.isSetSysClr()) fill.unsetSysClr();
70
71
    }
72
73
    public Color getFontColor(){
74
75
        CTTextCharacterProperties rPr = getRPr();
76
        if(rPr.isSetSolidFill()){
77
            CTSolidColorFillProperties fill = rPr.getSolidFill();
78
79
            if(fill.isSetSrgbClr()){
80
                CTSRgbColor clr = fill.getSrgbClr();
81
                byte[] rgb = clr.getVal();
82
                return new Color(0xFF & rgb[0], 0xFF & rgb[1], 0xFF & rgb[2]);
83
            }	
84
        }
85
86
        return new Color(0, 0, 0);
87
    }
88
89
    /**
90
     *
91
     * @param fontSize  font size in points.
92
     * The value of <code>-1</code> unsets the Sz attribute from the underlying xml bean
93
     */
94
    public void setFontSize(double fontSize){
95
        CTTextCharacterProperties rPr = getRPr();
96
        if(fontSize == -1.0) {
97
            if(rPr.isSetSz()) rPr.unsetSz();
98
        } else {
99
            if(fontSize < 1.0) {
100
                throw new IllegalArgumentException("Minimum font size is 1pt but was " + fontSize);
101
            }
102
103
            rPr.setSz((int)(100*fontSize));
104
        }
105
    }
106
107
    /**
108
     * @return font size in points or -1 if font size is not set.
109
     */
110
    public double getFontSize(){
111
        double scale = 1;
112
        double size = XSSFFont.DEFAULT_FONT_SIZE;	// default font size
113
        CTTextNormalAutofit afit = getParentParagraph().getParentShape().getTxBody().getBodyPr().getNormAutofit();
114
        if(afit != null) scale = (double)afit.getFontScale() / 100000;
115
116
        CTTextCharacterProperties rPr = getRPr();
117
        if(rPr.isSetSz()){
118
            size = rPr.getSz()*0.01;        
119
        }
120
121
        return size * scale;
122
    }
123
124
    /**
125
     *
126
     * @return the spacing between characters within a text run,
127
     * If this attribute is omitted then a value of 0 or no adjustment is assumed.
128
     */
129
    public double getCharacterSpacing(){
130
        CTTextCharacterProperties rPr = getRPr();
131
        if(rPr.isSetSpc()){
132
            return rPr.getSpc()*0.01;
133
        }
134
        return 0;
135
    }
136
137
    /**
138
     * Set the spacing between characters within a text run.
139
     * <p>
140
     * The spacing is specified in points. Positive values will cause the text to expand,
141
     * negative values to condense.
142
     * </p>
143
     *
144
     * @param spc  character spacing in points.
145
     */
146
    public void setCharacterSpacing(double spc){
147
        CTTextCharacterProperties rPr = getRPr();
148
        if(spc == 0.0) {
149
            if(rPr.isSetSpc()) rPr.unsetSpc();
150
        } else {
151
            rPr.setSpc((int)(100*spc));
152
        }
153
    }
154
155
    /**
156
     * Specifies the typeface, or name of the font that is to be used for this text run.
157
     *
158
     * @param typeface  the font to apply to this text run.
159
     * The value of <code>null</code> unsets the Typeface attribute from the underlying xml.
160
     */
161
    public void setFont(String typeface){
162
        setFontFamily(typeface, (byte)-1, (byte)-1, false);
163
    }
164
165
    public void setFontFamily(String typeface, byte charset, byte pictAndFamily, boolean isSymbol){
166
        CTTextCharacterProperties rPr = getRPr();
167
168
        if(typeface == null){
169
            if(rPr.isSetLatin()) rPr.unsetLatin();
170
            if(rPr.isSetCs()) rPr.unsetCs();
171
            if(rPr.isSetSym()) rPr.unsetSym();
172
        } else {
173
            if(isSymbol){
174
                CTTextFont font = rPr.isSetSym() ? rPr.getSym() : rPr.addNewSym();
175
                font.setTypeface(typeface);
176
            } else {
177
                CTTextFont latin = rPr.isSetLatin() ? rPr.getLatin() : rPr.addNewLatin();
178
                latin.setTypeface(typeface);
179
                if(charset != -1) latin.setCharset(charset);
180
                if(pictAndFamily != -1) latin.setPitchFamily(pictAndFamily);
181
            }
182
        }
183
    }
184
185
    /**
186
     * @return  font family or null if not set
187
     */
188
    public String getFontFamily(){
189
        CTTextCharacterProperties rPr = getRPr();
190
        CTTextFont font = rPr.getLatin();
191
        if(font != null){
192
            return font.getTypeface();
193
        }
194
        return XSSFFont.DEFAULT_FONT_NAME;
195
    }
196
197
    public byte getPitchAndFamily(){
198
        CTTextCharacterProperties rPr = getRPr();
199
        CTTextFont font = rPr.getLatin();
200
        if(font != null){
201
            return font.getPitchFamily();
202
        }
203
        return 0;
204
    }
205
206
    /**
207
     * Specifies whether a run of text will be formatted as strikethrough text.
208
     *
209
     * @param strike whether a run of text will be formatted as strikethrough text.
210
     */
211
    public void setStrikethrough(boolean strike) {
212
        getRPr().setStrike(strike ? STTextStrikeType.SNG_STRIKE : STTextStrikeType.NO_STRIKE);
213
    }
214
215
    /**
216
     * @return whether a run of text will be formatted as strikethrough text. Default is false.
217
     */
218
    public boolean isStrikethrough() {
219
        CTTextCharacterProperties rPr = getRPr();
220
        if(rPr.isSetStrike()){
221
            return rPr.getStrike() != STTextStrikeType.NO_STRIKE;
222
        }
223
        return false;
224
    }
225
226
    /**
227
     * @return whether a run of text will be formatted as a superscript text. Default is false.
228
     */
229
    public boolean isSuperscript() {
230
        CTTextCharacterProperties rPr = getRPr();
231
        if(rPr.isSetBaseline()){
232
            return rPr.getBaseline() > 0;
233
        }
234
        return false;
235
    }
236
237
    /**
238
     *  Set the baseline for both the superscript and subscript fonts.
239
     *  <p>
240
     *     The size is specified using a percentage.
241
     *     Positive values indicate superscript, negative values indicate subscript.
242
     *  </p>
243
     *
244
     * @param baselineOffset
245
     */
246
    public void setBaselineOffset(double baselineOffset){
247
        getRPr().setBaseline((int) baselineOffset * 1000);
248
    }
249
250
    /**
251
     * Set whether the text in this run is formatted as superscript.
252
     * Default base line offset is 30%
253
     *
254
     * @see #setBaselineOffset(double)
255
     */
256
    public void setSuperscript(boolean flag){
257
        setBaselineOffset(flag ? 30. : 0.);
258
    }
259
260
    /**
261
     * Set whether the text in this run is formatted as subscript.
262
     * Default base line offset is -25%.
263
     *
264
     * @see #setBaselineOffset(double)
265
     */
266
    public void setSubscript(boolean flag){
267
        setBaselineOffset(flag ? -25.0 : 0.);
268
    }
269
270
    /**
271
     * @return whether a run of text will be formatted as a superscript text. Default is false.
272
     */
273
    public boolean isSubscript() {
274
        CTTextCharacterProperties rPr = getRPr();
275
        if(rPr.isSetBaseline()){
276
            return rPr.getBaseline() < 0;
277
        }
278
        return false;
279
    }
280
281
    /**
282
     * @return whether a run of text will be formatted as a superscript text. Default is false.
283
     */
284
    public TextCap getTextCap() {    	
285
        CTTextCharacterProperties rPr = getRPr();
286
        if(rPr.isSetCap()){
287
            return TextCap.values()[rPr.getCap().intValue() - 1];
288
        }
289
        return TextCap.NONE;
290
    }
291
292
    /**
293
     * Specifies whether this run of text will be formatted as bold text
294
     *
295
     * @param bold whether this run of text will be formatted as bold text
296
     */
297
    public void setBold(boolean bold){
298
        getRPr().setB(bold);
299
    }
300
301
    /**
302
     * @return whether this run of text is formatted as bold text
303
     */
304
    public boolean isBold(){
305
        CTTextCharacterProperties rPr = getRPr();
306
        if(rPr.isSetB()){
307
            return rPr.getB();
308
        }
309
        return false;
310
    }
311
312
    /**
313
     * @param italic whether this run of text is formatted as italic text
314
     */
315
    public void setItalic(boolean italic){
316
        getRPr().setI(italic);
317
    }
318
319
    /**
320
     * @return whether this run of text is formatted as italic text
321
     */
322
    public boolean isItalic(){
323
        CTTextCharacterProperties rPr = getRPr();
324
        if(rPr.isSetI()){
325
            return rPr.getI();
326
        }
327
        return false;
328
    }
329
330
    /**
331
     * @param underline whether this run of text is formatted as underlined text
332
     */
333
    public void setUnderline(boolean underline) {
334
        getRPr().setU(underline ? STTextUnderlineType.SNG : STTextUnderlineType.NONE);
335
    }
336
337
    /**
338
     * @return whether this run of text is formatted as underlined text
339
     */
340
    public boolean isUnderline(){
341
        CTTextCharacterProperties rPr = getRPr();
342
        if(rPr.isSetU()){
343
            return rPr.getU() != STTextUnderlineType.NONE;
344
        }
345
        return false;
346
    }
347
348
    protected CTTextCharacterProperties getRPr(){
349
        return _r.isSetRPr() ? _r.getRPr() : _r.addNewRPr();
350
    }
351
352
    @Override
353
    public String toString(){
354
        return "[" + getClass() + "]" + getText();
355
    }
356
}
(-)src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFLineBreak.java (+45 lines)
Line 0 Link Here
1
/*
2
 *  ====================================================================
3
 *    Licensed to the Apache Software Foundation (ASF) under one or more
4
 *    contributor license agreements.  See the NOTICE file distributed with
5
 *    this work for additional information regarding copyright ownership.
6
 *    The ASF licenses this file to You under the Apache License, Version 2.0
7
 *    (the "License"); you may not use this file except in compliance with
8
 *    the License.  You may obtain a copy of the License at
9
 *
10
 *        http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 *    Unless required by applicable law or agreed to in writing, software
13
 *    distributed under the License is distributed on an "AS IS" BASIS,
14
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 *    See the License for the specific language governing permissions and
16
 *    limitations under the License.
17
 * ====================================================================
18
 */
19
20
package org.apache.poi.xssf.usermodel;
21
22
import org.openxmlformats.schemas.drawingml.x2006.main.CTRegularTextRun;
23
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties;
24
25
class XSSFLineBreak extends XSSFTextRun {
26
    private final CTTextCharacterProperties _brProps;
27
28
    XSSFLineBreak(CTRegularTextRun r, XSSFTextParagraph p, CTTextCharacterProperties brProps){
29
        super(r, p);
30
        _brProps = brProps;
31
    }
32
33
    @Override
34
    protected CTTextCharacterProperties getRPr(){
35
        return _brProps;
36
    }
37
38
    /**
39
     * Always throws IllegalStateException. You cannot change text of a line break.
40
     */
41
    public void setText(String text){
42
        throw new IllegalStateException("You cannot change text of a line break, it is always '\\n'");
43
    }
44
45
}
(-)src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java (+289 lines)
Lines 243-246 Link Here
243
243
244
244
245
    }
245
    }
246
    
247
    /**
248
     * ensure that font and color rich text attributes defined in a XSSFRichTextString
249
     * are passed to XSSFSimpleShape.
250
     *
251
     * See Bugzilla 54969.
252
     */
253
    public void testRichTextFontAndColor() {
254
    	XSSFWorkbook wb = new XSSFWorkbook();
255
        XSSFSheet sheet = wb.createSheet();
256
        XSSFDrawing drawing = sheet.createDrawingPatriarch();
257
258
        XSSFTextBox shape = drawing.createTextbox(new XSSFClientAnchor(0, 0, 0, 0, 2, 2, 3, 4));
259
        XSSFRichTextString rt = new XSSFRichTextString("Test String");
260
261
        XSSFFont font = wb.createFont();
262
        font.setColor(new XSSFColor(new Color(0, 128, 128)));
263
        font.setFontName("Arial");
264
        rt.applyFont(font);
265
266
        shape.setText(rt);
267
268
        CTTextParagraph pr = shape.getCTShape().getTxBody().getPArray(0);
269
        assertEquals(1, pr.sizeOfRArray());
270
271
        CTTextCharacterProperties rPr = pr.getRArray(0).getRPr();
272
        assertEquals("Arial", rPr.getLatin().getTypeface());
273
        assertTrue(Arrays.equals(
274
                new byte[]{0, (byte)128, (byte)128} ,
275
                rPr.getSolidFill().getSrgbClr().getVal()));
276
    	
277
    }
278
279
    /**
280
     * Test setText single paragraph to ensure backwards compatibility
281
     */
282
    public void testSetTextSingleParagraph() {
283
    
284
    	XSSFWorkbook wb = new XSSFWorkbook();
285
        XSSFSheet sheet = wb.createSheet();
286
        XSSFDrawing drawing = sheet.createDrawingPatriarch();
287
288
        XSSFTextBox shape = drawing.createTextbox(new XSSFClientAnchor(0, 0, 0, 0, 2, 2, 3, 4));
289
        XSSFRichTextString rt = new XSSFRichTextString("Test String");
290
291
        XSSFFont font = wb.createFont();
292
        font.setColor(new XSSFColor(new Color(0, 255, 255)));
293
        font.setFontName("Arial");
294
        rt.applyFont(font);
295
296
        shape.setText(rt);
297
        
298
        List<XSSFTextParagraph> paras = shape.getTextParagraphs();
299
        assertEquals(1, paras.size());
300
        assertEquals("Test String", paras.get(0).getText());
301
        
302
        List<XSSFTextRun> runs = paras.get(0).getTextRuns();
303
        assertEquals(1, runs.size());
304
        assertEquals("Arial", runs.get(0).getFontFamily());
305
        
306
        Color clr = runs.get(0).getFontColor(); 
307
        assertTrue(Arrays.equals(
308
                new int[] { 0, 255, 255 } ,
309
                new int[] { clr.getRed(), clr.getGreen(), clr.getBlue() }));
310
    }
311
    
312
    /**
313
     * Test addNewTextParagraph 
314
     */
315
    public void testAddNewTextParagraph() {
316
    
317
    	XSSFWorkbook wb = new XSSFWorkbook();
318
        XSSFSheet sheet = wb.createSheet();
319
        XSSFDrawing drawing = sheet.createDrawingPatriarch();
320
321
        XSSFTextBox shape = drawing.createTextbox(new XSSFClientAnchor(0, 0, 0, 0, 2, 2, 3, 4));
322
        
323
        XSSFTextParagraph para = shape.addNewTextParagraph();
324
        para.addNewTextRun().setText("Line 1");
325
                
326
        List<XSSFTextParagraph> paras = shape.getTextParagraphs();
327
        assertEquals(2, paras.size());	// this should be 2 as XSSFSimpleShape creates a default paragraph (no text), and then we add a string to that.
328
        
329
        List<XSSFTextRun> runs = para.getTextRuns();
330
        assertEquals(1, runs.size());
331
        assertEquals("Line 1", runs.get(0).getText());
332
    }
333
334
    /**
335
     * Test addNewTextParagraph using RichTextString
336
     */
337
    public void testAddNewTextParagraphWithRTS() {
338
    
339
    	XSSFWorkbook wb = new XSSFWorkbook();
340
        XSSFSheet sheet = wb.createSheet();
341
        XSSFDrawing drawing = sheet.createDrawingPatriarch();
342
343
        XSSFTextBox shape = drawing.createTextbox(new XSSFClientAnchor(0, 0, 0, 0, 2, 2, 3, 4));
344
        XSSFRichTextString rt = new XSSFRichTextString("Test Rich Text String");
345
346
        XSSFFont font = wb.createFont();        
347
        font.setColor(new XSSFColor(new Color(0, 255, 255)));
348
        font.setFontName("Arial");
349
        rt.applyFont(font);
350
        
351
        XSSFFont midfont = wb.createFont();
352
        midfont.setColor(new XSSFColor(new Color(0, 255, 0)));
353
        rt.applyFont(5, 14, midfont);	// set the text "Rich Text" to be green and the default font
354
        
355
        XSSFTextParagraph para = shape.addNewTextParagraph(rt);
356
        
357
        // Save and re-load it
358
        wb = XSSFTestDataSamples.writeOutAndReadBack(wb);
359
        sheet = wb.getSheetAt(0);
360
361
        // Check
362
        drawing = sheet.createDrawingPatriarch();
363
        
364
        List<XSSFShape> shapes = drawing.getShapes();
365
        assertEquals(1, shapes.size());
366
        assertTrue(shapes.get(0) instanceof XSSFSimpleShape); 
367
        
368
        XSSFSimpleShape sshape = (XSSFSimpleShape) shapes.get(0);
369
        
370
        List<XSSFTextParagraph> paras = sshape.getTextParagraphs();
371
        assertEquals(2, paras.size());	// this should be 2 as XSSFSimpleShape creates a default paragraph (no text), and then we add a string to that.  
372
        
373
        List<XSSFTextRun> runs = para.getTextRuns();
374
        assertEquals(3, runs.size());
375
        
376
        // first run properties
377
        assertEquals("Test ", runs.get(0).getText());
378
        assertEquals("Arial", runs.get(0).getFontFamily());
379
380
        Color clr = runs.get(0).getFontColor(); 
381
        assertTrue(Arrays.equals(
382
                new int[] { 0, 255, 255 } ,
383
                new int[] { clr.getRed(), clr.getGreen(), clr.getBlue() }));
384
385
        // second run properties        
386
        assertEquals("Rich Text", runs.get(1).getText());
387
        assertEquals(XSSFFont.DEFAULT_FONT_NAME, runs.get(1).getFontFamily());
388
389
        clr = runs.get(1).getFontColor(); 
390
        assertTrue(Arrays.equals(
391
                new int[] { 0, 255, 0 } ,
392
                new int[] { clr.getRed(), clr.getGreen(), clr.getBlue() }));        
393
        
394
        // third run properties
395
        assertEquals(" String", runs.get(2).getText());
396
        assertEquals("Arial", runs.get(2).getFontFamily());
397
        clr = runs.get(2).getFontColor(); 
398
        assertTrue(Arrays.equals(
399
                new int[] { 0, 255, 255 } ,
400
                new int[] { clr.getRed(), clr.getGreen(), clr.getBlue() }));
401
    }    
402
    
403
    /**
404
     * Test add multiple paragraphs and retrieve text
405
     */
406
    public void testAddMultipleParagraphs() {
407
    
408
    	XSSFWorkbook wb = new XSSFWorkbook();
409
        XSSFSheet sheet = wb.createSheet();
410
        XSSFDrawing drawing = sheet.createDrawingPatriarch();
411
412
        XSSFTextBox shape = drawing.createTextbox(new XSSFClientAnchor(0, 0, 0, 0, 2, 2, 3, 4));
413
        
414
        XSSFTextParagraph para = shape.addNewTextParagraph();
415
        para.addNewTextRun().setText("Line 1");
416
                
417
        para = shape.addNewTextParagraph();
418
        para.addNewTextRun().setText("Line 2");
419
        
420
        para = shape.addNewTextParagraph();
421
        para.addNewTextRun().setText("Line 3");
422
        
423
        List<XSSFTextParagraph> paras = shape.getTextParagraphs();
424
        assertEquals(4, paras.size());	// this should be 4 as XSSFSimpleShape creates a default paragraph (no text), and then we added 3 paragraphs
425
        assertEquals("Line 1\nLine 2\nLine 3", shape.getText());           
426
    }
427
    
428
    /**
429
     * Test setting the text, then adding multiple paragraphs and retrieve text
430
     */
431
    public void testSetAddMultipleParagraphs() {
432
    
433
    	XSSFWorkbook wb = new XSSFWorkbook();
434
        XSSFSheet sheet = wb.createSheet();
435
        XSSFDrawing drawing = sheet.createDrawingPatriarch();
436
437
        XSSFTextBox shape = drawing.createTextbox(new XSSFClientAnchor(0, 0, 0, 0, 2, 2, 3, 4));
438
        
439
        shape.setText("Line 1");
440
                
441
        XSSFTextParagraph para = shape.addNewTextParagraph();
442
        para.addNewTextRun().setText("Line 2");
443
        
444
        para = shape.addNewTextParagraph();
445
        para.addNewTextRun().setText("Line 3");
446
        
447
        List<XSSFTextParagraph> paras = shape.getTextParagraphs();
448
        assertEquals(3, paras.size());	// this should be 3 as we overwrote the default paragraph with setText, then added 2 new paragraphs
449
        assertEquals("Line 1\nLine 2\nLine 3", shape.getText());
450
    }
451
    
452
    /**
453
     * Test reading text from a textbox in an existing file
454
     */
455
    public void testReadTextBox(){
456
        XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("WithDrawing.xlsx");
457
        XSSFSheet sheet = wb.getSheetAt(0);
458
        //the sheet has one relationship and it is XSSFDrawing
459
        List<POIXMLDocumentPart> rels = sheet.getRelations();
460
        assertEquals(1, rels.size());
461
        assertTrue(rels.get(0) instanceof XSSFDrawing);
462
463
        XSSFDrawing drawing = (XSSFDrawing)rels.get(0);
464
        //sheet.createDrawingPatriarch() should return the same instance of XSSFDrawing
465
        assertSame(drawing, sheet.createDrawingPatriarch());
466
        String drawingId = drawing.getPackageRelationship().getId();
467
468
        //there should be a relation to this drawing in the worksheet
469
        assertTrue(sheet.getCTWorksheet().isSetDrawing());
470
        assertEquals(drawingId, sheet.getCTWorksheet().getDrawing().getId());
471
472
        List<XSSFShape> shapes = drawing.getShapes();
473
        assertEquals(6, shapes.size());
474
475
        assertTrue(shapes.get(4) instanceof XSSFSimpleShape);
476
477
        XSSFSimpleShape textbox = (XSSFSimpleShape) shapes.get(4); 
478
        assertEquals("Sheet with various pictures\n(jpeg, png, wmf, emf and pict)", textbox.getText());
479
    }
480
481
    /**
482
     * Test reading multiple paragraphs from a textbox in an existing file
483
     */
484
    public void testReadTextBoxParagraphs(){
485
        XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("WithTextBox.xlsx");
486
        XSSFSheet sheet = wb.getSheetAt(0);
487
        //the sheet has one relationship and it is XSSFDrawing
488
        List<POIXMLDocumentPart> rels = sheet.getRelations();
489
        assertEquals(1, rels.size());
490
        assertTrue(rels.get(0) instanceof XSSFDrawing);
491
492
        XSSFDrawing drawing = (XSSFDrawing)rels.get(0);
493
        //sheet.createDrawingPatriarch() should return the same instance of XSSFDrawing
494
        assertSame(drawing, sheet.createDrawingPatriarch());
495
        String drawingId = drawing.getPackageRelationship().getId();
496
497
        //there should be a relation to this drawing in the worksheet
498
        assertTrue(sheet.getCTWorksheet().isSetDrawing());
499
        assertEquals(drawingId, sheet.getCTWorksheet().getDrawing().getId());
500
501
        List<XSSFShape> shapes = drawing.getShapes();
502
        assertEquals(1, shapes.size());
503
504
        assertTrue(shapes.get(0) instanceof XSSFSimpleShape);
505
506
        XSSFSimpleShape textbox = (XSSFSimpleShape) shapes.get(0);
507
        
508
        List<XSSFTextParagraph> paras = textbox.getTextParagraphs();
509
        assertEquals(3, paras.size());
510
        
511
        assertEquals("Line 2", paras.get(1).getText());	// check content of second paragraph
512
513
        assertEquals("Line 1\nLine 2\nLine 3", textbox.getText());	// check content of entire textbox
514
        
515
        // check attributes of paragraphs
516
        assertEquals(TextAlign.LEFT, paras.get(0).getTextAlign());
517
        assertEquals(TextAlign.CENTER, paras.get(1).getTextAlign());
518
        assertEquals(TextAlign.RIGHT, paras.get(2).getTextAlign());
519
        
520
        Color clr = paras.get(0).getTextRuns().get(0).getFontColor(); 
521
        assertTrue(Arrays.equals(
522
                new int[] { 255, 0, 0 } ,
523
                new int[] { clr.getRed(), clr.getGreen(), clr.getBlue() }));
524
        
525
        clr = paras.get(1).getTextRuns().get(0).getFontColor(); 
526
        assertTrue(Arrays.equals(
527
                new int[] { 0, 255, 0 } ,
528
                new int[] { clr.getRed(), clr.getGreen(), clr.getBlue() }));
529
        
530
        clr = paras.get(2).getTextRuns().get(0).getFontColor(); 
531
        assertTrue(Arrays.equals(
532
                new int[] { 0, 0, 255 } ,
533
                new int[] { clr.getRed(), clr.getGreen(), clr.getBlue() }));
534
    }
246
}
535
}

Return to bug 55292