ref: a4a05ae434545d03ea8981e7aa4cc215bee577d7
parent: b22596ba7641a3f996b53ced14906e212a84220e
author: Noam Preil <noam@pixelhero.dev>
date: Mon Apr 24 02:21:37 EDT 2023
fix rendering!
--- a/op.c
+++ b/op.c
@@ -573,13 +573,10 @@
werrstr("Text objects must not be nested");
return 0;
}
- matidentity(p->TS.Tm);
- matidentity(p->TS.Tlm);
p->TS.inobj = 1;
- p->TS.TL = 0;
- p->TS.Tc = 0;
- p->TS.Tw = 0;
p->GSactive->Font.font = nil;
+ matidentity(p->TS.Tm);
+ matidentity(p->TS.Tlm);
return flagless(op);
}
@@ -723,12 +720,16 @@
return bufput(&p->buf, (uchar*)&c, 1) == 1;
}
+// Returns glyph width in TEXT SPACE units.
static double
glyphwidth(Page *p, ulong c)
{
- if(c >= p->GSactive->Font.first && c <= p->GSactive->Font.last)
- return (double)p->GSactive->Font.widths[c - p->GSactive->Font.first] / 1000;
- return (double)p->GSactive->Font.defwidth / 1000;
+ // TODO: type 3 fonts have explicit metrics? See 9.2.4 / 9.6.5 of the spec.
+ // For all other fonts, units are 1/1000th of text space
+ double gwidth = 420;
+// if(c >= p->GSactive->Font.first && c <= p->GSactive->Font.last)
+// gwidth = p->GSactive->Font.widths[c - p->GSactive->Font.first];
+ return gwidth / 1000;
}
static double
@@ -757,11 +758,10 @@
// Check if whitespace is needed
if(p->buf.sz > 1){
if(p->TS.y != Trm[5]){
- for(i = 0; i < (int)((p->TS.y - Trm[5]) / p->GSactive->Font.size) && i < 1; i += 1)
+ for(i = 0; i < (int)((Trm[5] - p->TS.y) / p->GSactive->Font.size / 1.5) && i < 2; i += 1)
if(bufput(&p->buf, (uchar*)"\n", 1) != 1)
return 0;
- }
- if(Trm[4] - p->TS.x > 14){
+ } else if(Trm[4] - p->TS.x > 5) {
if(bufput(&p->buf, (uchar*)" ", 1) != 1)
return 0;
}
@@ -822,11 +822,13 @@
int i;
for(i = 0; i < arraylen(arr); i += 1){
o = arrayget(arr, i);
- if(o->type == Ostr)
+ if(o->type == Ostr){
if(!tstr(p, o->str, o->len))
return 0;
- else
- mattrans(p->TS.Tm, 0 - (o->num.d / 1000), 0, p->TS.Tm);
+ }
+ else {
+ mattrans(p->TS.Tm, 0 - (p->GSactive->Font.size * o->num.d / 1000), 0, p->TS.Tm);
+ }
}
return flagless(op);
}
@@ -1373,7 +1375,7 @@
}
void
-ctminit(Page *p, double *ctm)
+ctminit(Page *p, double *ctm, double w, double h)
{
Object *cropbox;
double mx, my;
@@ -1381,17 +1383,26 @@
cropbox = pagecropbox(p);
mx = arrayget(cropbox, 2)->num.d;
my = arrayget(cropbox, 3)->num.d;
- ctm[0] = 850 / mx;
- ctm[3] = -1100 / my;
- ctm[5] = 1100;
+ ctm[0] = w / mx;
+ ctm[3] = 0-h / my;
+ ctm[5] = h;
}
+static void
+tsinit(Page *p)
+{
+ p->TS.TL = 0;
+ p->TS.Tc = 0;
+ p->TS.Tw = 0;
+}
+
void
gsinit(Page *p, GS *gs)
{
USED(p);
/* todo: actually initialize the full state */
- ctminit(p, gs->CTM);
+ ctminit(p, gs->CTM, 1100, 1300);
+ tsinit(p);
gs->LW = 1.0;
gs->LC = CapButt;
gs->LJ = JoinMiter;
@@ -1506,7 +1517,7 @@
}
p->GSactive = p->GS;
gsinit(p, p->GS);
- if((p->image = allocmemimage(Rect(0,0,850,1100), strtochan("r8g8b8"))) == nil){
+ if((p->image = allocmemimage(Rect(0,0,1100,1300), strtochan("r8g8b8"))) == nil){
werrstr("unable to allocate image: %r");
pagegsclean(p);
return 0;