• R/O
  • SSH

wp2latex: Commit

WP2LaTeX sources.


Commit MetaInfo

Revision3085a96f987c94a121cf8e37abb7a66edfab8dae (tree)
Zeit2022-04-27 16:49:23
AutorFojtik
CommiterFojtik

Log Message

Fix proper WPG2 plain text positioning & bounding box.

Ändern Zusammenfassung

Diff

diff -r 4b45f3b773e8 -r 3085a96f987c trunk/sources.cc/images.cc
--- a/trunk/sources.cc/images.cc Tue Apr 26 03:32:41 2022 +0200
+++ b/trunk/sources.cc/images.cc Wed Apr 27 09:49:23 2022 +0200
@@ -692,15 +692,15 @@
692692 pTxC->PosX = x;
693693 pTxC->PosY = y;
694694 if(fabs(dy)>0.01)
695- {
695+ {
696696 pTxC->PosY += dy/2;
697697 pTxC->PosY -= PSS.FontSize*2.66/2;
698698 pTxC->PosY += 0.15*PSS.FontSize*2.66/2; // Shift text slightly up
699- }
699+ }
700700 pTxC->FontOrientation = Angle;
701701 pTxC->RotCenterY = dy / 2;
702702 switch(pTxC->TextAllign&6)
703- {
703+ {
704704 case 2: pTxC->RotCenterX = dx / -2;
705705 pTxC->PosX += dx;
706706 break;
@@ -710,9 +710,9 @@
710710 default:
711711 pTxC->RotCenterX = dx / 2;
712712 break;
713- }
713+ }
714714 //VectList.AddObject(pTextCont);
715- }
715+ }
716716
717717 return pTxC;
718718 }
@@ -895,6 +895,15 @@
895895
896896 };
897897
898+class TWPG2ConvStatus: public TImgConvStatus
899+{
900+public:
901+ BYTE VTextAllign;
902+
903+ TWPG2ConvStatus(void): TImgConvStatus() {VTextAllign=0;}
904+};
905+
906+
898907 void TImgConvStatus::ClearBrushes(void)
899908 {
900909 if(BrushList==NULL) return;
@@ -928,8 +937,8 @@
928937 static void ProcessWPG2Token(TconvertedPass1 *cq, WPG2Record & Rec2,
929938 WPG2Start & StartWPG, Image & Img, APalette **Palette,
930939 PS_State & PSS, EmbeddedImg **EmImg,
931- DWORD & NewObjectPos, DWORD & ResourceEnd, Image **CurrImg,
932- TImgConvStatus & ImgSts, FloatBBox & bbx, VectorList &VectList)
940+ DWORD & NewObjectPos, DWORD & ResourceEnd,
941+ TWPG2ConvStatus & ImgSts, FloatBBox & bbx, VectorList &VectList)
933942 {
934943 #ifdef DEBUG
935944 fprintf(cq->log,"\n#ProcessWPG2Token() ");fflush(cq->log);
@@ -965,7 +974,7 @@
965974 cq->ActualPos = ftell(cq->wpd);
966975 NewObjectPos = cq->ActualPos + Rec2b.RecordLength;
967976
968- ProcessWPG2Token(cq, Rec2b, StartWPG, Img, Palette, PSS, EmImg, NewObjectPos, ResourceEnd, CurrImg,
977+ ProcessWPG2Token(cq, Rec2b, StartWPG, Img, Palette, PSS, EmImg, NewObjectPos, ResourceEnd, /*CurrImg,*/
969978 ImgSts, bbx, VectList);
970979 if(Rec2b.Type==0x31 || Rec2b.Type==0x32)
971980 {
@@ -1021,7 +1030,7 @@
10211030 (*Palette)->R(i,fgetc(cq->wpd));
10221031 (*Palette)->G(i,fgetc(cq->wpd));
10231032 (*Palette)->B(i,fgetc(cq->wpd));
1024- fgetc(cq->wpd);//Opacity?
1033+ fgetc(cq->wpd); //Opacity?
10251034 }
10261035 }
10271036 }
@@ -1132,36 +1141,40 @@
11321141 delete TxC;
11331142 else
11341143 {
1135- if(fabs(ImgSts.dx)<0.1) ImgSts.dx=0.5f*mm2WPGu(PSS.FontSize);
1136- if(fabs(ImgSts.dy)<0.1) ImgSts.dy=mm2WPGu(PSS.FontSize);
1137- UpdateBBox(bbx, ImgSts.RotAngle, ImgSts.x, ImgSts.y-0.2f*ImgSts.dy, ImgSts.dx, 1.3f*ImgSts.dy); // Calculate bbx in [WPU].
1144+ if(ImgSts.dx<1e-6)
1145+ {
1146+ TxC->CalculateExtent(ImgSts.dx,ImgSts.dy);
1147+ ImgSts.dx = mm2WPGu(ImgSts.dx);
1148+ ImgSts.dy = mm2WPGu(ImgSts.dy) / 1.3;
1149+ if(ImgSts.VTextAllign == 0)
1150+ TxC->PosY -= 0.8*mm2WPGu(PSS.FontSize); // Shift text paint to the line bottom.
1151+ UpdateBBox(bbx, ImgSts.RotAngle, ImgSts.x, ImgSts.y, ImgSts.dx, ImgSts.dy); // Calculate bbx in [WPU].
1152+ }
1153+ else
1154+ {
1155+ if(fabs(ImgSts.dx)<0.1) ImgSts.dx=0.5f*mm2WPGu(PSS.FontSize);
1156+ if(fabs(ImgSts.dy)<0.1) ImgSts.dy=mm2WPGu(PSS.FontSize);
1157+ UpdateBBox(bbx, ImgSts.RotAngle, ImgSts.x, ImgSts.y-0.2f*ImgSts.dy, ImgSts.dx, 1.3f*ImgSts.dy); // Calculate bbx in [WPU].
1158+ }
11381159 VectList.AddObject(TxC);
11391160 }
11401161 }
1141-/*
1162+
11421163 #ifdef _DEBUG
1143- float ccc = mm2WPGu(3);
1144- ccc = WPGu2mm(ccc);
1145- ccc = WPGu2PSu(200);
1146- ccc = PSu2WPGu(ccc);
1147-
11481164 // Debug purpose rectangle
1149- VectorRectangle *Vr = new VectorRectangle(WPGu2PSu(ImgSts.y), WPGu2PSu(ImgSts.y+mm2WPGu(PSS.FontSize)),
1150- WPGu2PSu(ImgSts.x), WPGu2PSu(ImgSts.x+ImgSts.dx));
1165+ VectorRectangle *Vr = new VectorRectangle(ImgSts.y, ImgSts.y+mm2WPGu(PSS.FontSize),
1166+ ImgSts.x, ImgSts.x+ImgSts.dx);
11511167 PSS.FillPattern = FILL_NONE;
11521168 Vr->AttribFromPSS(PSS);
11531169 VectList.AddObject(Vr);
11541170
1155- Vr = new VectorRectangle(WPGu2PSu(ImgSts.y), WPGu2PSu(ImgSts.y+mm2WPGu(3)),
1156- WPGu2PSu(ImgSts.x), WPGu2PSu(ImgSts.x+mm2WPGu(3)));
1171+ Vr = new VectorRectangle(ImgSts.y, ImgSts.y+mm2WPGu(3),
1172+ ImgSts.x, ImgSts.x+mm2WPGu(3));
11571173 PSS.FillPattern = FILL_NONE;
11581174 Vr->AttribFromPSS(PSS);
11591175 VectList.AddObject(Vr);
1160-
1161- ccc = WPGu2mm(ImgSts.dy);
1162- ccc = WPGu2mm(ImgSts.dx);
11631176 #endif
1164-*/
1177+
11651178 strcpy(cq->ObjType,"Text Data");
11661179 break;
11671180 }
@@ -1189,7 +1202,7 @@
11891202 cq->ActualPos = ftell(cq->wpd);
11901203
11911204 DWORD NewObjectPos2 = cq->ActualPos + Rec2b.RecordLength;
1192- ProcessWPG2Token(cq, Rec2b, StartWPG, Img, Palette, PSS, EmImg, NewObjectPos2, NewObjectPos, CurrImg,
1205+ ProcessWPG2Token(cq, Rec2b, StartWPG, Img, Palette, PSS, EmImg, NewObjectPos2, NewObjectPos, /*CurrImg,*/
11931206 ImgSts, bbx, VectList);
11941207
11951208 if(NewObjectPos2 != ftell(cq->wpd))
@@ -1425,6 +1438,7 @@
14251438 ImgSts.x = WPG._2TxtLine.Xref;
14261439 ImgSts.y = WPG._2TxtLine.Yref;
14271440 ImgSts.dx = ImgSts.dy = 0;
1441+ ImgSts.VTextAllign = WPG._2TxtLine.VAlign;
14281442 TRx.RotAngle = 0;
14291443 TRx.ApplyTransform(ImgSts.x,ImgSts.y);
14301444 UpdateBBox(bbx, 0, ImgSts.x, ImgSts.y, 0, 0);
@@ -1508,7 +1522,7 @@
15081522 cq->ActualPos = ftell(cq->wpd);
15091523 NewObjectPos = cq->ActualPos + Rec2b.RecordLength;
15101524
1511- ProcessWPG2Token(cq, Rec2b, StartWPG, Img, Palette, PSS, EmImg, NewObjectPos, ResourceEnd, CurrImg,
1525+ ProcessWPG2Token(cq, Rec2b, StartWPG, Img, Palette, PSS, EmImg, NewObjectPos, ResourceEnd, /*CurrImg,*/
15121526 ImgSts, bbxIn, VectListIn);
15131527 }
15141528 cq->recursion--;
@@ -1559,7 +1573,7 @@
15591573 cq->ActualPos = ftell(cq->wpd);
15601574 NewObjectPos = cq->ActualPos + Rec2b.RecordLength;
15611575
1562- ProcessWPG2Token(cq, Rec2b, StartWPG, Img, Palette, PSS, EmImg, NewObjectPos, ResourceEnd, CurrImg,
1576+ ProcessWPG2Token(cq, Rec2b, StartWPG, Img, Palette, PSS, EmImg, NewObjectPos, ResourceEnd, /*CurrImg,*/
15631577 ImgSts, bbxIn, VectListIn);
15641578 }
15651579 cq->recursion--;
@@ -2452,7 +2466,7 @@
24522466 PSS.FirstTimeFix = true;
24532467 memset(&PSS.FillColor, 0xFF, sizeof(PSS.FillColor));
24542468 memset(&PSS.FillBackground, 0xFF, sizeof(PSS.FillBackground));
2455- TImgConvStatus ImgSts;
2469+ TWPG2ConvStatus ImgSts;
24562470
24572471 //VectorList VectList;
24582472 while(cq->ActualPos < ResourceEnd)
@@ -2467,7 +2481,7 @@
24672481 if(feof(cq->wpd)) break;
24682482
24692483 ProcessWPG2Token(cq, Rec2, StartWPG2, Img, &Palette,
2470- PSS, EmImg, NewObject, ResourceEnd, &CurrImg,
2484+ PSS, EmImg, NewObject, ResourceEnd, /*&CurrImg,*/
24712485 ImgSts, bbx, VectList);
24722486
24732487 if(NewObject!=ftell(cq->wpd))
diff -r 4b45f3b773e8 -r 3085a96f987c trunk/sources.cc/images/vecimage.cc
--- a/trunk/sources.cc/images/vecimage.cc Tue Apr 26 03:32:41 2022 +0200
+++ b/trunk/sources.cc/images/vecimage.cc Wed Apr 27 09:49:23 2022 +0200
@@ -1489,6 +1489,82 @@
14891489 }
14901490
14911491
1492+void TextContainer::CalculateExtent(float &TextWidth, float &TextHeight) const
1493+{
1494+float CurPosX = 0;
1495+float LastLineSz = 0;
1496+
1497+ TextWidth = TextHeight = 0;
1498+ if(Text!=NULL && TextObjects>0)
1499+ {
1500+ for(int i=0; i<TextObjects; i++)
1501+ {
1502+ if(Text[i]!=NULL)
1503+ {
1504+ LastLineSz = Text[i]->size;
1505+ int j = 0;
1506+
1507+ string str;
1508+ while(j < Text[i]->contents.length())
1509+ {
1510+ char ch = Text[i]->contents[j];
1511+ if(ch=='\\')
1512+ {
1513+ j++;
1514+ while(j < Text[i]->contents.length())
1515+ {
1516+ ch = Text[i]->contents[j];
1517+ j++;
1518+ if(ch==' ') break;
1519+ if(ch=='{')
1520+ {
1521+ while(j < Text[i]->contents.length())
1522+ {
1523+ ch = Text[i]->contents[j];
1524+ j++;
1525+ if(ch=='}') break;
1526+ str += ch;
1527+ }
1528+ break;
1529+ }
1530+ }
1531+ continue;
1532+ }
1533+ str += ch;
1534+ j++;
1535+ }
1536+
1537+ j = 0;
1538+ while(j < str.length())
1539+ {
1540+ char ch = str[j];
1541+ switch(ch)
1542+ {
1543+ case '\n': if(CurPosX>TextWidth) TextWidth=CurPosX;
1544+ CurPosX = 0;
1545+ TextHeight += LastLineSz;
1546+ break;
1547+ case 'l':
1548+ case 'i': CurPosX += 0.26 * LastLineSz;
1549+ break;
1550+ case 'm': CurPosX += 0.71 * LastLineSz;
1551+ break;
1552+ default: if(isupper(ch))
1553+ CurPosX += 0.5 * LastLineSz;
1554+ else
1555+ CurPosX += 0.44 * LastLineSz;
1556+ break;
1557+ }
1558+ j++;
1559+ }
1560+ }
1561+ }
1562+ if(CurPosX>TextWidth) TextWidth=CurPosX;
1563+ TextHeight += LastLineSz;
1564+ }
1565+}
1566+
1567+
14921568 #ifdef _DEBUG
14931569 void TextContainer::Dump2File(FILE *F) const
14941570 {
diff -r 4b45f3b773e8 -r 3085a96f987c trunk/sources.cc/images/vecimage.h
--- a/trunk/sources.cc/images/vecimage.h Tue Apr 26 03:32:41 2022 +0200
+++ b/trunk/sources.cc/images/vecimage.h Wed Apr 27 09:49:23 2022 +0200
@@ -469,6 +469,7 @@
469469 void AddText(temp_string contents, const PS_State &PSS);
470470 void AddText(temp_string contents, const char *font, const PS_State &PSS);
471471
472+ void CalculateExtent(float &TextWidth, float &TextHeight) const;
472473 bool isEmpty(void) const;
473474
474475 TextObject **Text;
diff -r 4b45f3b773e8 -r 3085a96f987c trunk/sources.cc/wp2latex.cc
--- a/trunk/sources.cc/wp2latex.cc Tue Apr 26 03:32:41 2022 +0200
+++ b/trunk/sources.cc/wp2latex.cc Wed Apr 27 09:49:23 2022 +0200
@@ -413,7 +413,7 @@
413413
414414 void ShowCopyright(void)
415415 {
416- puts(_("\nThis program and related files are copyright (c) 1996-2017 Fojtik Jaroslav."
416+ puts(_("\nThis program and related files are copyright (c) 1996-2022 Fojtik Jaroslav."
417417 "\nThis code can be redistributed and/or modified under the terms of the GNU"
418418 "\nGeneral Public License available from: http://www.gnu.org/copyleft/gpl.html."
419419 "\nWith one additional requirement:"
diff -r 4b45f3b773e8 -r 3085a96f987c trunk/sources.cc/wp2latex.h
--- a/trunk/sources.cc/wp2latex.h Tue Apr 26 03:32:41 2022 +0200
+++ b/trunk/sources.cc/wp2latex.h Wed Apr 27 09:49:23 2022 +0200
@@ -18,7 +18,7 @@
1818 #define LineLength 80 /* Split lines after more than LineLength charcters */
1919
2020 #define VersionWP2L "3.pre107"
21-#define VersionDate "23 Apr 2022" /* day (space) month (space) full year */
21+#define VersionDate "25 Apr 2022" /* day (space) month (space) full year */
2222
2323 #ifndef false
2424 #define false 0
Show on old repository browser