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
109Rune otfglyph2rune(Otf *o, int g);109Rune otfglyph2rune(Otf *o, int g);
110 110
111Glyf *otfglyf(Otf *o, int index);111Glyf *otfglyf(Otf *o, int index);
112GlyfImage *otfdrawglyf(Otf *o, Glyf *g, double ppem);112GlyfImage *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
110Rune otfglyph2rune(Otf *o, int g);110Rune otfglyph2rune(Otf *o, int g);
111 111
112Glyf *otfglyf(Otf *o, int index);112Glyf *otfglyf(Otf *o, int index);
113GlyfImage *otfdrawglyf(Otf *o, Glyf *g, double ppem);113GlyfImage *otfdrawglyf(Otf *o, Glyf *g, double ppem, double scaleX, double scaleY);
114 114
115typedef struct SubHeader SubHeader;115typedef struct SubHeader SubHeader;
116typedef struct MapGroup MapGroup;116typedef struct MapGroup MapGroup;
rast.c+11−10
@@ -548,15 +548,15 @@ glyfmaxnpts(Glyf *g) · 547 unmodified lines
548}548}
549 549
550GlyfImage *550GlyfImage *
551otfdrawglyf(Otf *o, Glyf *g, double ppem)551otfdrawglyf(Otf *o, Glyf *g, double ppem, double scaleX, double scaleY)
552{552{
553 int i, j, maxptstotal, maxpts, ngs, w, h, npx, baseline;553 int i, j, maxptstotal, maxpts, ngs, w, h, npx, baseline;
554 Glyf *gs[MAXCOMPONENTS];554 Glyf *gs[MAXCOMPONENTS];
555 ComponentGlyph *cg;555 ComponentGlyph *cg;
556 Sval scale, offY;
557 SegQ *s₀, *s, *p;556 SegQ *s₀, *s, *p;
558 GlyfImage *im;557 GlyfImage *im;
559 Sval bb[4];558 Sval bb[4];
559 Sval offY;
560 Spt *pts;560 Spt *pts;
561 561
562 ngs = 0;562 ngs = 0;
@@ -589,15 +589,16 @@ FIXME metrics (lsb+rsb) · 26 unmodified lines
589*/589*/
590 590
591 pts = calloc(1, maxpts*sizeof(*pts) + maxptstotal/2*sizeof(*s));591 pts = calloc(1, maxpts*sizeof(*pts) + maxptstotal/2*sizeof(*s));
592 scale = ppem / o->td.head->unitsPerEm;592 scaleX *= ppem / o->td.head->unitsPerEm;
593 bb[0] = g->xMin*scale;593 scaleY *= ppem / o->td.head->unitsPerEm;
594 bb[1] = g->yMin*scale;594 bb[0] = g->xMin*scaleX;
595 bb[2] = g->xMax*scale;595 bb[1] = g->yMin*scaleY;
596 bb[3] = g->yMax*scale;596 bb[2] = g->xMax*scaleX;
597 bb[3] = g->yMax*scaleY;
597 s = s₀ = (SegQ*)(pts + maxpts);598 s = s₀ = (SegQ*)(pts + maxpts);
598 cg = g->component;599 cg = g->component;
599 for(i = 0; i < ngs; i++){600 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;
601 if(cg != nil){602 if(cg != nil){
602 if(cg->flags & CGLYPH_FL_SIGNED_XY){603 if(cg->flags & CGLYPH_FL_SIGNED_XY){
603 dx = cg->dx;604 dx = cg->dx;
@@ -614,8 +615,8 @@ FIXME metrics (lsb+rsb) · 10 unmodified lines
614 dx *= gscaleX;615 dx *= gscaleX;
615 dy *= gscaleY;616 dy *= gscaleY;
616 }else{617 }else{
617 dx *= scale;618 dx *= scaleX;
618 dy *= scale;619 dy *= scaleY;
619 }620 }
620/* FIXME rounding621/* FIXME rounding
621 if(cg->flags & CGLYPH_FL_ROUND_TO_GRID_XY){622 if(cg->flags & CGLYPH_FL_ROUND_TO_GRID_XY){
test.h+13−3
@@ -10,12 +10,14 @@ printusage(Otfile *f) · 9 unmodified lines
10 f->print(f->aux, " -m: print out glyph ids or render them all as a map (with -p)\n");10 f->print(f->aux, " -m: print out glyph ids or render them all as a map (with -p)\n");
11 f->print(f->aux, " -R: ignore glyphs that do not represent valid runes\n");11 f->print(f->aux, " -R: ignore glyphs that do not represent valid runes\n");
12 f->print(f->aux, " -H: highlight a specific glyph in the map by its ID\n");12 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");
13 f->print(f->aux, "Specifying -m more than once adds guide lines\n");15 f->print(f->aux, "Specifying -m more than once adds guide lines\n");
14 f->print(f->aux, "Specifying -m more than twice makes empty pixels filled out\n");16 f->print(f->aux, "Specifying -m more than twice makes empty pixels filled out\n");
15}17}
16 18
17static int gind = -1, map, highlight = -1, runesonly;19static int gind = -1, map, highlight = -1, runesonly;
18static double ppem;20static double ppem, scaleX = 1, scaleY = 1;
19static Rune rune = NoRune;21static Rune rune = NoRune;
20 22
21static int23static int
@@ -76,6 +78,8 @@ dumpmap(Otfile *f, GlyfImage **im, int n) · 54 unmodified lines
76 break;78 break;
77 79
78 for(x = 0; i < j; i++){80 for(x = 0; i < j; i++){
81 if(im[i] == nil)
82 continue;
79 u8int *lt = b + ((y + prebase - (im[i]->h+im[i]->baseline))*bw + x)*3;83 u8int *lt = b + ((y + prebase - (im[i]->h+im[i]->baseline))*bw + x)*3;
80 x += im[i]->w + gap;84 x += im[i]->w + gap;
81 for(d = 0; d < im[i]->h; d++, lt += bw*3){85 for(d = 0; d < im[i]->h; d++, lt += bw*3){
@@ -148,7 +152,7 @@ glypherr: · 66 unmodified lines
148 return -1;152 return -1;
149 }153 }
150 if(ppem > 0 && g->numberOfContours != 0){154 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)
152 goto glypherr;156 goto glypherr;
153 }else if(ppem <= 0){157 }else if(ppem <= 0){
154 out->print(out->aux, "%d (%s):\n", i,158 out->print(out->aux, "%d (%s):\n", i,
@@ -171,7 +175,7 @@ glypherr: · 16 unmodified lines
171 goto glypherr;175 goto glypherr;
172 }else if(ppem > 0){176 }else if(ppem > 0){
173 GlyfImage *im;177 GlyfImage *im;
174 if((im = otfdrawglyf(o, g, ppem)) == nil)178 if((im = otfdrawglyf(o, g, ppem, scaleX, scaleY)) == nil)
175 goto glypherr;179 goto glypherr;
176 if(out->write != otfdiscard && dumpmap(out, &im, 1) != 0)180 if(out->write != otfdiscard && dumpmap(out, &im, 1) != 0)
177 return -1;181 return -1;
@@ -218,6 +222,12 @@ errboth: \ · 40 unmodified lines
218 case 'R': \222 case 'R': \
219 runesonly++; \223 runesonly++; \
220 break; \224 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; \
221 default: \231 default: \
222 usage(&out); \232 usage(&out); \
223 }ARGEND \233 }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