ref: 46473dabaa54037f2d0376653dfab75ff3c03301
parent: 5d347485e57b91134cd4f68b05a8a783896fed5c
author: Noam Preil <noam@pixelhero.dev>
date: Thu Apr 7 12:03:30 EDT 2022
op: implement word spacing
--- a/op.c
+++ b/op.c
@@ -362,8 +362,8 @@
static int
tswspace(Op *op, Page *p)
{
- USED(op, p);
- return 0;
+ p->TS.Tw = arrayget(p->stack, 0)->num.d;
+ return 1;
}
static int
@@ -449,6 +449,7 @@
p->TS.inobj = 1;
p->TS.TL = 0;
p->TS.Tc = 0;
+ p->TS.Tw = 0;
p->GSactive->Font.font = nil;
return flagless(op);
}
@@ -617,14 +618,16 @@
else
w0 = (double)p->GSactive->Font.defwidth / 1000;
tx = w0 * p->GSactive->Font.size + p->TS.Tc;
+ if(c == ' ')
+ tx += p->TS.Tw;
// 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)
+ for(i = 0; i < (int)((p->TS.y - Trm[5]) / p->GSactive->Font.size) && i < 1; i += 1)
if(bufput(&p->buf, (uchar*)"\n", 1) != 1)
return 0;
}
- if(Trm[4] - p->TS.x > 2.5){
+ if(Trm[4] - p->TS.x > 14){
if(bufput(&p->buf, (uchar*)" ", 1) != 1)
return 0;
}
@@ -677,8 +680,7 @@
return 0;
}
else{
- double shift = 0 - (p->GSactive->Font.size * o->num.d / 1000);
- if(!tmove(p, shift, 0, 0))
+ if(!tmove(p, 0 - (o->num.d / 1000), 0, 0))
return 0;
}
}
--- a/pdf.h
+++ b/pdf.h
@@ -142,7 +142,7 @@
double Tlm[6]; /* text line matrix */
/* Tracks if we're in a text object; nesting is verboten */
int inobj;
- double TL, Tc;
+ double TL, Tc, Tw;
/* Temporary, for pdf2txt functionality: tracks the last character's position so we know whether whitespace is needed */
double x, y;
};