History

otfdrawglyf: add horizontal and vertical glyph scaling

Sigrid Solveig Haflínudóttir committed 2 years ago

Commit a100cd91 parent 2cfe3c24 files · +26 −15Browse files

Unified · Split

4 files
  1. otf.h.in +1 −1
  2. plan9/otf.h +1 −1
  3. rast.c +11 −10
  4. test.h +13 −3
otf.h.in+1−1
@@ -109,4 +109,4 @@ int otfrune2glyph(Otf *o, Rune r); · 108 unmodified lines
109109 Rune otfglyph2rune(Otf *o, int g);
110110
111111 Glyf *otfglyf(Otf *o, int index);
112−GlyfImage *otfdrawglyf(Otf *o, Glyf *g, double ppem);
112+GlyfImage *otfdrawglyf(Otf *o, Glyf *g, double ppem, double scaleX, double scaleY);
plan9/otf.h+1−1
@@ -110,7 +110,7 @@ int otfrune2glyph(Otf *o, Rune r); · 109 unmodified lines
110110 Rune otfglyph2rune(Otf *o, int g);
111111
112112 Glyf *otfglyf(Otf *o, int index);
113−GlyfImage *otfdrawglyf(Otf *o, Glyf *g, double ppem);
113+GlyfImage *otfdrawglyf(Otf *o, Glyf *g, double ppem, double scaleX, double scaleY);
114114
115115 typedef struct SubHeader SubHeader;
116116 typedef struct MapGroup MapGroup;
rast.c+11−10
@@ -548,15 +548,15 @@ glyfmaxnpts(Glyf *g) · 547 unmodified lines
548548 }
549549
550550 GlyfImage *
551−otfdrawglyf(Otf *o, Glyf *g, double ppem)
551+otfdrawglyf(Otf *o, Glyf *g, double ppem, double scaleX, double scaleY)
552552 {
553553 int i, j, maxptstotal, maxpts, ngs, w, h, npx, baseline;
554554 Glyf *gs[MAXCOMPONENTS];
555555 ComponentGlyph *cg;
556− Sval scale, offY;
557556 SegQ *s₀, *s, *p;
558557 GlyfImage *im;
559558 Sval bb[4];
559+ Sval offY;
560560 Spt *pts;
561561
562562 ngs = 0;
@@ -589,15 +589,16 @@ FIXME metrics (lsb+rsb) · 26 unmodified lines
589589 */
590590
591591 pts = calloc(1, maxpts*sizeof(*pts) + maxptstotal/2*sizeof(*s));
592− scale = ppem / o->td.head->unitsPerEm;
593− bb[0] = g->xMin*scale;
594− bb[1] = g->yMin*scale;
595− bb[2] = g->xMax*scale;
596− bb[3] = g->yMax*scale;
592+ scaleX *= ppem / o->td.head->unitsPerEm;
593+ scaleY *= ppem / o->td.head->unitsPerEm;
594+ bb[0] = g->xMin*scaleX;
595+ bb[1] = g->yMin*scaleY;
596+ bb[2] = g->xMax*scaleX;
597+ bb[3] = g->yMax*scaleY;
597598 s = s₀ = (SegQ*)(pts + maxpts);
598599 cg = g->component;
599600 for(i = 0; i < ngs; i++){
600− Sval dx = 0, dy = 0, gscaleX = scale, gscaleY = scale;
601+ Sval dx = 0, dy = 0, gscaleX = scaleX, gscaleY = scaleY;
601602 if(cg != nil){
602603 if(cg->flags & CGLYPH_FL_SIGNED_XY){
603604 dx = cg->dx;
@@ -614,8 +615,8 @@ FIXME metrics (lsb+rsb) · 10 unmodified lines
614615 dx *= gscaleX;
615616 dy *= gscaleY;
616617 }else{
617− dx *= scale;
618− dy *= scale;
618+ dx *= scaleX;
619+ dy *= scaleY;
619620 }
620621 /* FIXME rounding
621622 if(cg->flags & CGLYPH_FL_ROUND_TO_GRID_XY){
test.h+13−3
@@ -10,12 +10,14 @@ printusage(Otfile *f) · 9 unmodified lines
1010 f->print(f->aux, " -m: print out glyph ids or render them all as a map (with -p)\n");
1111 f->print(f->aux, " -R: ignore glyphs that do not represent valid runes\n");
1212 f->print(f->aux, " -H: highlight a specific glyph in the map by its ID\n");
13+ f->print(f->aux, " -x: horizontal scale factor\n");
14+ f->print(f->aux, " -y: vertical scale factor\n");
1315 f->print(f->aux, "Specifying -m more than once adds guide lines\n");
1416 f->print(f->aux, "Specifying -m more than twice makes empty pixels filled out\n");
1517 }
1618
1719 static int gind = -1, map, highlight = -1, runesonly;
18−static double ppem;
20+static double ppem, scaleX = 1, scaleY = 1;
1921 static Rune rune = NoRune;
2022
2123 static int
@@ -76,6 +78,8 @@ dumpmap(Otfile *f, GlyfImage **im, int n) · 54 unmodified lines
7678 break;
7779
7880 for(x = 0; i < j; i++){
81+ if(im[i] == nil)
82+ continue;
7983 u8int *lt = b + ((y + prebase - (im[i]->h+im[i]->baseline))*bw + x)*3;
8084 x += im[i]->w + gap;
8185 for(d = 0; d < im[i]->h; d++, lt += bw*3){
@@ -148,7 +152,7 @@ glypherr: · 66 unmodified lines
148152 return -1;
149153 }
150154 if(ppem > 0 && g->numberOfContours != 0){
151− if((im[i] = otfdrawglyf(o, g, ppem)) == nil)
155+ if((im[i] = otfdrawglyf(o, g, ppem, scaleX, scaleY)) == nil)
152156 goto glypherr;
153157 }else if(ppem <= 0){
154158 out->print(out->aux, "%d (%s):\n", i,
@@ -171,7 +175,7 @@ glypherr: · 16 unmodified lines
171175 goto glypherr;
172176 }else if(ppem > 0){
173177 GlyfImage *im;
174− if((im = otfdrawglyf(o, g, ppem)) == nil)
178+ if((im = otfdrawglyf(o, g, ppem, scaleX, scaleY)) == nil)
175179 goto glypherr;
176180 if(out->write != otfdiscard && dumpmap(out, &im, 1) != 0)
177181 return -1;
@@ -218,6 +222,12 @@ errboth: \ · 40 unmodified lines
218222 case 'R': \
219223 runesonly++; \
220224 break; \
225+ case 'x': \
226+ scaleX = strtod(EARGF(usage(&out)), nil); \
227+ break; \
228+ case 'y': \
229+ scaleY = strtod(EARGF(usage(&out)), nil); \
230+ break; \
221231 default: \
222232 usage(&out); \
223233 }ARGEND \

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