History

fix rendering!

Noam Preil committed 3 years ago

Commit a4a05ae1 parent b22596b1 file · +31 −20Browse files

Unified · Split

op.c+31−20
@@ -573,13 +573,10 @@ tobegin(Op *op, Page *p) · 572 unmodified lines
573573 werrstr("Text objects must not be nested");
574574 return 0;
575575 }
576− matidentity(p->TS.Tm);
577− matidentity(p->TS.Tlm);
578576 p->TS.inobj = 1;
579− p->TS.TL = 0;
580− p->TS.Tc = 0;
581− p->TS.Tw = 0;
582577 p->GSactive->Font.font = nil;
578+ matidentity(p->TS.Tm);
579+ matidentity(p->TS.Tlm);
583580 return flagless(op);
584581 }
585582
@@ -723,12 +720,16 @@ writepatched(Page *p, uchar c) · 137 unmodified lines
723720 return bufput(&p->buf, (uchar*)&c, 1) == 1;
724721 }
725722
723+// Returns glyph width in TEXT SPACE units.
726724 static double
727725 glyphwidth(Page *p, ulong c)
728726 {
729− if(c >= p->GSactive->Font.first && c <= p->GSactive->Font.last)
730− return (double)p->GSactive->Font.widths[c - p->GSactive->Font.first] / 1000;
731− return (double)p->GSactive->Font.defwidth / 1000;
727+ // TODO: type 3 fonts have explicit metrics? See 9.2.4 / 9.6.5 of the spec.
728+ // For all other fonts, units are 1/1000th of text space
729+ double gwidth = 420;
730+// if(c >= p->GSactive->Font.first && c <= p->GSactive->Font.last)
731+// gwidth = p->GSactive->Font.widths[c - p->GSactive->Font.first];
732+ return gwidth / 1000;
732733 }
733734
734735 static double
@@ -757,11 +758,10 @@ tchar(Page *p, ulong c) · 22 unmodified lines
757758 // Check if whitespace is needed
758759 if(p->buf.sz > 1){
759760 if(p->TS.y != Trm[5]){
760− for(i = 0; i < (int)((p->TS.y - Trm[5]) / p->GSactive->Font.size) && i < 1; i += 1)
761+ for(i = 0; i < (int)((Trm[5] - p->TS.y) / p->GSactive->Font.size / 1.5) && i < 2; i += 1)
761762 if(bufput(&p->buf, (uchar*)"\n", 1) != 1)
762763 return 0;
763− }
764− if(Trm[4] - p->TS.x > 14){
764+ } else if(Trm[4] - p->TS.x > 5) {
765765 if(bufput(&p->buf, (uchar*)" ", 1) != 1)
766766 return 0;
767767 }
@@ -822,11 +822,13 @@ thshowarr(Op *op, Page *p) · 54 unmodified lines
822822 int i;
823823 for(i = 0; i < arraylen(arr); i += 1){
824824 o = arrayget(arr, i);
825− if(o->type == Ostr)
825+ if(o->type == Ostr){
826826 if(!tstr(p, o->str, o->len))
827827 return 0;
828− else
829− mattrans(p->TS.Tm, 0 - (o->num.d / 1000), 0, p->TS.Tm);
828+ }
829+ else {
830+ mattrans(p->TS.Tm, 0 - (p->GSactive->Font.size * o->num.d / 1000), 0, p->TS.Tm);
831+ }
830832 }
831833 return flagless(op);
832834 }
@@ -1373,7 +1375,7 @@ pagecropbox(Page *p) · 540 unmodified lines
13731375 }
13741376
13751377 void
1376−ctminit(Page *p, double *ctm)
1378+ctminit(Page *p, double *ctm, double w, double h)
13771379 {
13781380 Object *cropbox;
13791381 double mx, my;
@@ -1381,9 +1383,17 @@ ctminit(Page *p, double *ctm) · 1 unmodified line
13811383 cropbox = pagecropbox(p);
13821384 mx = arrayget(cropbox, 2)->num.d;
13831385 my = arrayget(cropbox, 3)->num.d;
1384− ctm[0] = 850 / mx;
1385− ctm[3] = -1100 / my;
1386− ctm[5] = 1100;
1386+ ctm[0] = w / mx;
1387+ ctm[3] = 0-h / my;
1388+ ctm[5] = h;
1389+}
1390+
1391+static void
1392+tsinit(Page *p)
1393+{
1394+ p->TS.TL = 0;
1395+ p->TS.Tc = 0;
1396+ p->TS.Tw = 0;
13871397 }
13881398
13891399 void
@@ -1391,7 +1401,8 @@ gsinit(Page *p, GS *gs) · 1 unmodified line
13911401 {
13921402 USED(p);
13931403 /* todo: actually initialize the full state */
1394− ctminit(p, gs->CTM);
1404+ ctminit(p, gs->CTM, 1100, 1300);
1405+ tsinit(p);
13951406 gs->LW = 1.0;
13961407 gs->LC = CapButt;
13971408 gs->LJ = JoinMiter;
@@ -1506,7 +1517,7 @@ pagerender(Page *p) · 108 unmodified lines
15061517 }
15071518 p->GSactive = p->GS;
15081519 gsinit(p, p->GS);
1509− if((p->image = allocmemimage(Rect(0,0,850,1100), strtochan("r8g8b8"))) == nil){
1520+ if((p->image = allocmemimage(Rect(0,0,1100,1300), strtochan("r8g8b8"))) == nil){
15101521 werrstr("unable to allocate image: %r");
15111522 pagegsclean(p);
15121523 return 0;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t