1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
|
From cfc3157868f691b70c2f0a6daa3c387ca6ef42a9 Mon Sep 17 00:00:00 2001
From: Tor Lillqvist <tml@collabora.com>
Date: Tue, 10 Nov 2015 00:20:42 +0200
Subject: [PATCH 1/3] Port glyphy-demo to Windows
You will need glew and freeglut to build and run it.
I have a VS solution for glyphy-demo, but did not commit that as I did
not bother to do it "properly", with different projects for the
library and the demo executable, Release and Debug configurations etc.
---
demo/demo-buffer.cc | 11 ++++
demo/demo-common.h | 6 ++
demo/demo-font.cc | 131 +++++++++++++++++++++++++++++++++++---------
demo/demo-font.h | 21 ++++++-
demo/demo-view.cc | 3 +-
demo/glyphy-demo.cc | 134 ++++++++++++++++++++++++++++++++++++++++++++-
src/Makefile.am | 1 +
src/glyphy-windows.h | 152 +++++++++++++++++++++++++++++++++++++++++++++++++++
8 files changed, 429 insertions(+), 30 deletions(-)
create mode 100755 src/glyphy-windows.h
diff --git a/demo/demo-buffer.cc b/demo/demo-buffer.cc
index 698f4ee..8ce5b34 100644
--- a/demo/demo-buffer.cc
+++ b/demo/demo-buffer.cc
@@ -106,7 +106,11 @@ demo_buffer_add_text (demo_buffer_t *buffer,
demo_font_t *font,
double font_size)
{
+#ifndef _WIN32
FT_Face face = demo_font_get_face (font);
+#else
+ HDC hdc = demo_font_get_face (font);
+#endif
glyphy_point_t top_left = buffer->cursor;
buffer->cursor.y += font_size /* * font->ascent */;
unsigned int unicode;
@@ -138,7 +142,14 @@ demo_buffer_add_text (demo_buffer_t *buffer,
continue;
}
+#ifndef _WIN32
unsigned int glyph_index = FT_Get_Char_Index (face, unicode);
+#else
+ wchar_t wc = unicode; /* FIXME: What about non-BMP chars? */
+ WORD glyph_index;
+ if (GetGlyphIndicesW (hdc, &wc, 1, &glyph_index, GGI_MARK_NONEXISTING_GLYPHS) == GDI_ERROR)
+ die ("GetGlyphIndicesW failed");
+#endif
glyph_info_t gi;
demo_font_lookup_glyph (font, glyph_index, &gi);
diff --git a/demo/demo-common.h b/demo/demo-common.h
index dd0feb9..da56a88 100644
--- a/demo/demo-common.h
+++ b/demo/demo-common.h
@@ -44,6 +44,12 @@
# define HAVE_GLUT 1
#endif
+#ifdef _WIN32
+# define HAVE_GL 1
+# define HAVE_GLEW 1
+# define HAVE_GLUT 1
+#endif
+
/* Get Glew out of the way. */
#ifdef HAVE_GLEW
# include <GL/glew.h>
diff --git a/demo/demo-font.cc b/demo/demo-font.cc
index 4ed4b53..b43b1e3 100644
--- a/demo/demo-font.cc
+++ b/demo/demo-font.cc
@@ -22,19 +22,30 @@
#include "demo-font.h"
+#ifndef _WIN32
#include <glyphy-freetype.h>
+#endif
-#include <ext/hash_map>
-
-using namespace __gnu_cxx; /* This is ridiculous */
+#ifdef _WIN32
+#include <glyphy-windows.h>
+#endif
+#include <map>
+#include <vector>
-typedef hash_map<unsigned int, glyph_info_t> glyph_cache_t;
+typedef std::map<unsigned int, glyph_info_t> glyph_cache_t;
struct demo_font_t {
unsigned int refcount;
+#ifndef _WIN32
FT_Face face;
+#endif
+
+#ifdef _WIN32
+ HDC face; /* A memory DC that has the font instance selected into it */
+#endif
+
glyph_cache_t *glyph_cache;
demo_atlas_t *atlas;
glyphy_arc_accumulator_t *acc;
@@ -48,7 +59,13 @@ struct demo_font_t {
};
demo_font_t *
-demo_font_create (FT_Face face,
+demo_font_create (
+#ifndef _WIN32
+ FT_Face face,
+#endif
+#ifdef _WIN32
+ HDC face,
+#endif
demo_atlas_t *atlas)
{
demo_font_t *font = (demo_font_t *) calloc (1, sizeof (demo_font_t));
@@ -88,7 +105,12 @@ demo_font_destroy (demo_font_t *font)
}
+#ifndef _WIN32
FT_Face
+#endif
+#ifdef _WIN32
+HDC
+#endif
demo_font_get_face (demo_font_t *font)
{
return font->face;
@@ -103,27 +125,28 @@ demo_font_get_atlas (demo_font_t *font)
static glyphy_bool_t
accumulate_endpoint (glyphy_arc_endpoint_t *endpoint,
- vector<glyphy_arc_endpoint_t> *endpoints)
+ std::vector<glyphy_arc_endpoint_t> *endpoints)
{
endpoints->push_back (*endpoint);
return true;
}
static void
-encode_ft_glyph (demo_font_t *font,
- unsigned int glyph_index,
- double tolerance_per_em,
- glyphy_rgba_t *buffer,
- unsigned int buffer_len,
- unsigned int *output_len,
- unsigned int *nominal_width,
- unsigned int *nominal_height,
- glyphy_extents_t *extents,
- double *advance)
+encode_glyph (demo_font_t *font,
+ unsigned int glyph_index,
+ double tolerance_per_em,
+ glyphy_rgba_t *buffer,
+ unsigned int buffer_len,
+ unsigned int *output_len,
+ unsigned int *nominal_width,
+ unsigned int *nominal_height,
+ glyphy_extents_t *extents,
+ double *advance)
{
/* Used for testing only */
#define SCALE (1. * (1 << 0))
+#ifndef _WIN32
FT_Face face = font->face;
if (FT_Err_Ok != FT_Load_Glyph (face,
glyph_index,
@@ -141,7 +164,7 @@ encode_ft_glyph (demo_font_t *font,
unsigned int upem = face->units_per_EM;
double tolerance = upem * tolerance_per_em; /* in font design units */
double faraway = double (upem) / (MIN_FONT_SIZE * M_SQRT2);
- vector<glyphy_arc_endpoint_t> endpoints;
+ std::vector<glyphy_arc_endpoint_t> endpoints;
glyphy_arc_accumulator_reset (font->acc);
glyphy_arc_accumulator_set_tolerance (font->acc, tolerance);
@@ -151,6 +174,55 @@ encode_ft_glyph (demo_font_t *font,
if (FT_Err_Ok != glyphy_freetype(outline_decompose) (&face->glyph->outline, font->acc))
die ("Failed converting glyph outline to arcs");
+#endif
+
+#ifdef _WIN32
+ HDC hdc = font->face;
+
+ GLYPHMETRICS glyph_metrics;
+ MAT2 matrix;
+
+ matrix.eM11.value = 1;
+ matrix.eM11.fract = 0;
+ matrix.eM12.value = 0;
+ matrix.eM12.fract = 0;
+ matrix.eM21.value = 0;
+ matrix.eM21.fract = 0;
+ matrix.eM22.value = 1;
+ matrix.eM22.fract = 0;
+
+ DWORD size = GetGlyphOutlineW (hdc, glyph_index, GGO_NATIVE|GGO_GLYPH_INDEX, &glyph_metrics, 0, NULL, &matrix);
+ if (size == GDI_ERROR)
+ die ("GetGlyphOutlineW failed");
+ std::vector<char> buf(size);
+ size = GetGlyphOutlineW (hdc, glyph_index, GGO_NATIVE|GGO_GLYPH_INDEX, &glyph_metrics, size, buf.data(), &matrix);
+ if (size == GDI_ERROR)
+ die ("GetGlyphOutlineW failed");
+
+ size = GetGlyphOutlineW (hdc, glyph_index, GGO_METRICS|GGO_GLYPH_INDEX, &glyph_metrics, 0, NULL, &matrix);
+ if (size == GDI_ERROR)
+ die ("GetGlyphOutlineW failed");
+
+ OUTLINETEXTMETRICW outline_text_metric;
+ if (!GetOutlineTextMetricsW (hdc, sizeof (OUTLINETEXTMETRICW), &outline_text_metric))
+ die ("GetOutlineTextMetricsW failed");
+
+ unsigned int upem = outline_text_metric.otmEMSquare;
+ double tolerance = upem * tolerance_per_em; /* in font design units */
+ double faraway = double (upem) / (MIN_FONT_SIZE * M_SQRT2);
+ std::vector<glyphy_arc_endpoint_t> endpoints;
+
+ fprintf(stderr, "upem=%u tolerance=%f faraway=%f\n", upem, tolerance, faraway);
+
+ glyphy_arc_accumulator_reset (font->acc);
+ glyphy_arc_accumulator_set_tolerance (font->acc, tolerance);
+ glyphy_arc_accumulator_set_callback (font->acc,
+ (glyphy_arc_endpoint_accumulator_callback_t) accumulate_endpoint,
+ &endpoints);
+
+ if (0 != glyphy_windows(outline_decompose) ((TTPOLYGONHEADER *) buf.data(), buf.size(), font->acc))
+ die ("Failed converting glyph outline to arcs");
+#endif
assert (glyphy_arc_accumulator_get_error (font->acc) <= tolerance);
@@ -192,7 +264,14 @@ encode_ft_glyph (demo_font_t *font,
glyphy_extents_scale (extents, 1. / upem, 1. / upem);
glyphy_extents_scale (extents, SCALE, SCALE);
+#ifndef _WIN32
*advance = face->glyph->metrics.horiAdvance / (double) upem;
+#endif
+
+#ifdef _WIN32
+ *advance = glyph_metrics.gmCellIncX / (double) upem; /* ??? */
+ fprintf(stderr, "======> Advance: %f\n", *advance);
+#endif
if (0)
LOGI ("gid%3u: endpoints%3d; err%3g%%; tex fetch%4.1f; mem%4.1fkb\n",
@@ -217,15 +296,15 @@ _demo_font_upload_glyph (demo_font_t *font,
glyphy_rgba_t buffer[4096 * 16];
unsigned int output_len;
- encode_ft_glyph (font,
- glyph_index,
- TOLERANCE,
- buffer, ARRAY_LEN (buffer),
- &output_len,
- &glyph_info->nominal_w,
- &glyph_info->nominal_h,
- &glyph_info->extents,
- &glyph_info->advance);
+ encode_glyph (font,
+ glyph_index,
+ TOLERANCE,
+ buffer, ARRAY_LEN (buffer),
+ &output_len,
+ &glyph_info->nominal_w,
+ &glyph_info->nominal_h,
+ &glyph_info->extents,
+ &glyph_info->advance);
glyph_info->is_empty = glyphy_extents_is_empty (&glyph_info->extents);
if (!glyph_info->is_empty)
diff --git a/demo/demo-font.h b/demo/demo-font.h
index ddc45ed..d4e75ff 100644
--- a/demo/demo-font.h
+++ b/demo/demo-font.h
@@ -22,9 +22,17 @@
#include "demo-common.h"
#include "demo-atlas.h"
+#ifndef _WIN32
#include <ft2build.h>
#include FT_FREETYPE_H
+#endif
+#ifdef _WIN32
+#include <windows.h>
+#define DEFAULT_FONT "Calibri"
+#undef near
+#undef far
+#endif
typedef struct {
glyphy_extents_t extents;
@@ -40,7 +48,13 @@ typedef struct {
typedef struct demo_font_t demo_font_t;
demo_font_t *
-demo_font_create (FT_Face face,
+demo_font_create (
+#ifndef _WIN32
+ FT_Face face,
+#endif
+#ifdef _WIN32
+ HDC hdc,
+#endif
demo_atlas_t *atlas);
demo_font_t *
@@ -50,7 +64,12 @@ void
demo_font_destroy (demo_font_t *font);
+#ifndef _WIN32
FT_Face
+#endif
+#ifdef _WIN32
+HDC
+#endif
demo_font_get_face (demo_font_t *font);
demo_atlas_t *
diff --git a/demo/demo-view.cc b/demo/demo-view.cc
index b60fc24..fee3e23 100644
--- a/demo/demo-view.cc
+++ b/demo/demo-view.cc
@@ -27,8 +27,9 @@ extern "C" {
#include "matrix4x4.h"
}
+#ifndef _WIN32
#include <sys/time.h>
-
+#endif
struct demo_view_t {
unsigned int refcount;
diff --git a/demo/glyphy-demo.cc b/demo/glyphy-demo.cc
index cf412cc..bc71dff 100644
--- a/demo/glyphy-demo.cc
+++ b/demo/glyphy-demo.cc
@@ -20,14 +20,15 @@
#include <config.h>
#endif
+#ifndef _WIN32
#include <libgen.h>
+#include <unistd.h>
+#endif
#include <stdio.h>
#include <string.h>
-#include <unistd.h>
#include <ctype.h>
#include <stdlib.h>
-
#include "demo-buffer.h"
#include "demo-font.h"
#include "demo-view.h"
@@ -39,6 +40,90 @@ static demo_buffer_t *buffer;
#define WINDOW_W 700
#define WINDOW_H 700
+#ifdef _WIN32
+
+static int isroot(const char *path)
+{
+ return ((strlen(path) == 1 && path[0] == '/') ||
+ (strlen(path) == 3 && isalpha(path[0]) && path[1] == ':' && (path[2] == '/' || path[2] == '\\')));
+}
+
+static char *basename(char *path)
+{
+ if (path == NULL || *path == '\0')
+ return ".";
+
+ while ((path[strlen(path)-1] == '/' ||
+ path[strlen(path)-1] == '\\') &&
+ !isroot(path))
+ path[strlen(path)-1] = '\0';
+
+ if (isroot(path))
+ return path;
+
+ char *slash = strrchr(path, '/');
+ char *backslash = strrchr(path, '\\');
+
+ if (slash != NULL && (backslash == NULL || backslash < slash))
+ return slash + 1;
+ else if (backslash != NULL && (slash == NULL || slash < backslash))
+ return backslash + 1;
+ else
+ return path;
+}
+
+static int opterr = 1;
+static int optind = 1;
+static int optopt;
+static char *optarg;
+
+static int getopt(int argc, char *argv[], char *opts)
+{
+ static int sp = 1;
+ int c;
+ char *cp;
+
+ if (sp == 1) {
+ if (optind >= argc ||
+ argv[optind][0] != '-' || argv[optind][1] == '\0')
+ return EOF;
+ else if (!strcmp(argv[optind], "--")) {
+ optind++;
+ return EOF;
+ }
+ }
+ optopt = c = argv[optind][sp];
+ if (c == ':' || !(cp = strchr(opts, c))) {
+ fprintf(stderr, ": illegal option -- %c\n", c);
+ if (argv[optind][++sp] == '\0') {
+ optind++;
+ sp = 1;
+ }
+ return '?';
+ }
+ if (*++cp == ':') {
+ if (argv[optind][sp+1] != '\0')
+ optarg = &argv[optind++][sp+1];
+ else if(++optind >= argc) {
+ fprintf(stderr, ": option requires an argument -- %c\n", c);
+ sp = 1;
+ return '?';
+ } else
+ optarg = argv[optind++];
+ sp = 1;
+ } else {
+ if (argv[optind][++sp] == '\0') {
+ sp = 1;
+ optind++;
+ }
+ optarg = NULL;
+ }
+
+ return c;
+}
+
+#endif
+
static void
reshape_func (int width, int height)
{
@@ -161,6 +246,7 @@ main (int argc, char** argv)
vu = demo_view_create (st);
demo_view_print_help (vu);
+#ifndef _WIN32
FT_Library ft_library;
FT_Init_FreeType (&ft_library);
FT_Face ft_face;
@@ -173,6 +259,42 @@ main (int argc, char** argv)
if (!ft_face)
die ("Failed to open font file");
demo_font_t *font = demo_font_create (ft_face, demo_glstate_get_atlas (st));
+#endif
+
+#ifdef _WIN32
+ HDC hdc = CreateCompatibleDC (GetDC (NULL));
+ if (hdc == NULL)
+ die ("GetDC or CreateCompatibleDC failed");
+
+ /* First create an instance of the font at size 10 to get the OUTLINETEXTMETRIC from which to get
+ * the font's em unit. Then, to get an unmodified not grid-fitted glyph outline, create it anew at
+ * that size. That is as the doc for GetGlyphOutline() suggests.
+ */
+ HFONT hfont = CreateFontA(10, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_TT_ONLY_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY, FF_DONTCARE, font_path);
+ if (hfont == NULL)
+ die ("CreateFontA failed");
+
+ HFONT old_hfont = (HFONT) SelectObject (hdc, hfont);
+ if (old_hfont == NULL)
+ die ("SelectObject failed");
+
+ OUTLINETEXTMETRICW outline_text_metric;
+ if (!GetOutlineTextMetricsW (hdc, sizeof (OUTLINETEXTMETRICW), &outline_text_metric))
+ die ("GetOutlineTextMetricsW failed");
+
+ SelectObject (hdc, old_hfont);
+
+ hfont = CreateFontA (outline_text_metric.otmEMSquare, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_TT_ONLY_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY, FF_DONTCARE, font_path);
+ if (hfont == NULL)
+ die ("CreateFontA failed");
+
+ old_hfont = (HFONT) SelectObject (hdc, hfont);
+ if (old_hfont == NULL)
+ die ("SelectObject failed");
+
+ demo_font_t *font = demo_font_create (hdc, demo_glstate_get_atlas (st));
+
+#endif
buffer = demo_buffer_create ();
glyphy_point_t top_left = {0, 0};
@@ -187,8 +309,16 @@ main (int argc, char** argv)
demo_buffer_destroy (buffer);
demo_font_destroy (font);
+#ifndef _WIN32
FT_Done_Face (ft_face);
FT_Done_FreeType (ft_library);
+#endif
+
+#ifdef _WIN32
+ SelectObject (hdc, old_hfont);
+ DeleteObject (hfont);
+ DeleteDC (hdc);
+#endif
demo_view_destroy (vu);
demo_glstate_destroy (st);
diff --git a/src/Makefile.am b/src/Makefile.am
index 004afd3..ecb76e0 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -32,6 +32,7 @@ libglyphy_la_SOURCES = \
PUBLICHEADERS = \
glyphy.h \
glyphy-freetype.h \
+ glyphy-windows.h \
$(NULL)
SHADERS = \
glyphy-common.glsl \
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -32,6 +32,7 @@ libglyphy_la_SOURCES = \
PUBLICHEADERS = \
glyphy.h \
glyphy-freetype.h \
+ glyphy-windows.h \
$(NULL)
SHADERS = \
diff --git a/src/glyphy-windows.h b/src/glyphy-windows.h
new file mode 100755
index 0000000..b3c11c8
--- /dev/null
+++ b/src/glyphy-windows.h
@@ -0,0 +1,152 @@
+/*
+ * Copyright 2012 Google, Inc. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Google Author(s): Behdad Esfahbod, Maysum Panju
+ */
+
+/* Intentionally doesn't have include guards */
+
+#include "glyphy.h"
+
+#include <windows.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+#ifndef GLYPHY_WINDOWS__PREFIX
+#define GLYPHY_WINDOWS_PREFIX glyphy_windows_
+#endif
+
+#ifndef glyphy_windows
+#define glyphy_windows(name) GLYPHY_PASTE (GLYPHY_WINDOWS_PREFIX, name)
+#endif
+
+static double fixed_to_double(FIXED f)
+{
+ return f.value + f.fract / double(0x10000);
+}
+
+static int
+glyphy_windows(move_to) (const POINTFX *to,
+ glyphy_arc_accumulator_t *acc)
+{
+ glyphy_point_t p1 = {fixed_to_double(to->x), fixed_to_double(to->y)};
+ glyphy_arc_accumulator_close_path (acc);
+ glyphy_arc_accumulator_move_to (acc, &p1);
+ return glyphy_arc_accumulator_successful (acc) ? 0 : -1;
+}
+
+static int
+glyphy_windows(line_to) (const POINTFX *to,
+ glyphy_arc_accumulator_t *acc)
+{
+ glyphy_point_t p1 = {fixed_to_double(to->x), fixed_to_double(to->y)};
+ glyphy_arc_accumulator_line_to (acc, &p1);
+ return glyphy_arc_accumulator_successful (acc) ? 0 : -1;
+}
+
+static int
+glyphy_windows(conic_to) (const POINTFX *control,
+ const glyphy_point_t *p2,
+ glyphy_arc_accumulator_t *acc)
+{
+ glyphy_point_t p1 = {fixed_to_double(control->x), fixed_to_double(control->y)};
+ glyphy_arc_accumulator_conic_to (acc, &p1, p2);
+ return glyphy_arc_accumulator_successful (acc) ? 0 : -1;
+}
+
+/* See https://support.microsoft.com/en-us/kb/87115 */
+
+static int
+glyphy_windows(outline_decompose) (const TTPOLYGONHEADER *outline,
+ size_t outline_size,
+ glyphy_arc_accumulator_t *acc)
+{
+ const TTPOLYGONHEADER *polygon = outline;
+ const TTPOLYGONHEADER *outline_end = (const TTPOLYGONHEADER*) ((char *)outline + outline_size);
+
+ int polygon_count = 0;
+ while (polygon < outline_end)
+ {
+ if (((char *)polygon + polygon->cb) > (char *) outline_end)
+ die ("TTPOLYGONHEADER record too large for enclosing data");
+
+ assert(polygon->dwType == TT_POLYGON_TYPE);
+
+ if (glyphy_windows(move_to) (&polygon->pfxStart, acc) == -1)
+ return -1;
+
+ const TTPOLYCURVE *curve = (const TTPOLYCURVE*) (polygon + 1);
+ const TTPOLYCURVE *curve_end = (const TTPOLYCURVE*) ((char *)polygon + polygon->cb);
+ int curve_count = 0;
+ while (curve < curve_end)
+ {
+ if (((char *) &curve->apfx[curve->cpfx]) > (char *) curve_end)
+ die ("TTPOLYCURVE record too large for enclosing TTPOLYGONHEADER\n");
+
+ switch (curve->wType)
+ {
+ case TT_PRIM_LINE:
+ {
+ int i;
+ for (i = 0; i < curve->cpfx; i++) {
+ if (glyphy_windows(line_to) (&curve->apfx[i], acc) == -1)
+ return -1;
+ }
+
+ /* A final TT_PRIM_LINE in a contour automatically closes to the contour start */
+ if ((const TTPOLYCURVE *) ((char *) &curve->apfx[curve->cpfx]) == curve_end)
+ if (glyphy_windows(line_to) (&polygon->pfxStart, acc) == -1)
+ return -1;
+ }
+ break;
+ case TT_PRIM_QSPLINE:
+ {
+ int i = 0;
+ while (i < curve->cpfx) {
+ const POINTFX *control = &curve->apfx[i];
+ i++;
+ const POINTFX *p2 = &curve->apfx[i];
+ glyphy_point_t p2pt = {fixed_to_double(p2->x), fixed_to_double(p2->y)};
+ if (i == curve->cpfx - 1) {
+ i++;
+ } else {
+ p2pt.x = (p2pt.x + fixed_to_double(control->x)) / 2;
+ p2pt.y = (p2pt.y + fixed_to_double(control->y)) / 2;
+ }
+ if (glyphy_windows(conic_to) (control, &p2pt, acc) == -1)
+ return -1;
+ }
+ /* If the last point of the contour was not the start point, draw a closing line to it */
+ if ((const TTPOLYCURVE *) ((char *) &curve->apfx[curve->cpfx]) == curve_end)
+ if (glyphy_windows(line_to) (&polygon->pfxStart, acc) == -1)
+ return -1;
+ }
+ break;
+ default:
+ die ("Unexpected record in TTPOLYCURVE");
+ }
+ curve = (const TTPOLYCURVE *) ((char *) &curve->apfx[curve->cpfx]);
+ }
+ polygon = (const TTPOLYGONHEADER *) curve_end;
+ }
+ return 0;
+}
+
+#ifdef __cplusplus
+}
+#endif
--
2.4.3
From 6d4196a2dc59324d14d3d4d721929e851277da97 Mon Sep 17 00:00:00 2001
From: Tor Lillqvist <tml@collabora.com>
Date: Tue, 10 Nov 2015 13:35:17 +0200
Subject: [PATCH 2/3] Bin leftover printf
---
demo/demo-font.cc | 3 ---
1 file changed, 3 deletions(-)
diff --git a/demo/demo-font.cc b/demo/demo-font.cc
index b43b1e3..c28778e 100644
--- a/demo/demo-font.cc
+++ b/demo/demo-font.cc
@@ -212,8 +212,6 @@ encode_glyph (demo_font_t *font,
double faraway = double (upem) / (MIN_FONT_SIZE * M_SQRT2);
std::vector<glyphy_arc_endpoint_t> endpoints;
- fprintf(stderr, "upem=%u tolerance=%f faraway=%f\n", upem, tolerance, faraway);
-
glyphy_arc_accumulator_reset (font->acc);
glyphy_arc_accumulator_set_tolerance (font->acc, tolerance);
glyphy_arc_accumulator_set_callback (font->acc,
@@ -270,7 +268,6 @@ encode_glyph (demo_font_t *font,
#ifdef _WIN32
*advance = glyph_metrics.gmCellIncX / (double) upem; /* ??? */
- fprintf(stderr, "======> Advance: %f\n", *advance);
#endif
if (0)
--
2.4.3
|