OLD | NEW |
| (Empty) |
1 /* | |
2 | |
3 ** Copyright 2006, The Android Open Source Project | |
4 | |
5 ** | |
6 | |
7 ** Licensed under the Apache License, Version 2.0 (the "License"); | |
8 | |
9 ** you may not use this file except in compliance with the License. | |
10 | |
11 ** You may obtain a copy of the License at | |
12 | |
13 ** | |
14 | |
15 ** http://www.apache.org/licenses/LICENSE-2.0 | |
16 | |
17 ** | |
18 | |
19 ** Unless required by applicable law or agreed to in writing, software | |
20 | |
21 ** distributed under the License is distributed on an "AS IS" BASIS, | |
22 | |
23 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
24 | |
25 ** See the License for the specific language governing permissions and | |
26 | |
27 ** limitations under the License. | |
28 | |
29 */ | |
30 | |
31 | |
32 | |
33 #include "SkString.h" | |
34 | |
35 //#include "SkStream.h" | |
36 | |
37 | |
38 | |
39 #include "SkFontHost.h" | |
40 | |
41 #include "SkDescriptor.h" | |
42 | |
43 #include "SkThread.h" | |
44 | |
45 | |
46 | |
47 #ifdef WIN32 | |
48 | |
49 #include "windows.h" | |
50 | |
51 #include "tchar.h" | |
52 | |
53 | |
54 | |
55 // client3d has to undefine this for now | |
56 | |
57 #define CAN_USE_LOGFONT_NAME | |
58 | |
59 | |
60 | |
61 static SkMutex gFTMutex; | |
62 | |
63 | |
64 | |
65 // these globals are loaded (once) by get_default_font() | |
66 | |
67 static LOGFONT gDefaultFont = {0}; | |
68 | |
69 | |
70 | |
71 static const uint16_t BUFFERSIZE = (16384 - 32); | |
72 | |
73 static uint8_t glyphbuf[BUFFERSIZE]; | |
74 | |
75 | |
76 | |
77 // Give 1MB font cache budget | |
78 | |
79 #define FONT_CACHE_MEMORY_BUDGET (1024 * 1024) | |
80 | |
81 | |
82 | |
83 static inline FIXED SkFixedToFIXED(SkFixed x) { | |
84 | |
85 return *(FIXED*)(&x); | |
86 | |
87 } | |
88 | |
89 | |
90 | |
91 static inline FIXED SkScalarToFIXED(SkScalar x) { | |
92 | |
93 return SkFixedToFIXED(SkScalarToFixed(x)); | |
94 | |
95 } | |
96 | |
97 | |
98 | |
99 // This will generate a unique ID based on the fontname + fontstyle | |
100 | |
101 // and also used by upper layer | |
102 | |
103 uint32_t FontFaceChecksum(const TCHAR *q, SkTypeface::Style style) | |
104 | |
105 { | |
106 | |
107 if (!q) return style; | |
108 | |
109 | |
110 | |
111 // From "Performance in Practice of String Hashing Functions" | |
112 | |
113 // Ramakrishna & Zobel | |
114 | |
115 const uint32_t L = 5; | |
116 | |
117 const uint32_t R = 2; | |
118 | |
119 | |
120 | |
121 uint32_t h = 0x12345678; | |
122 | |
123 while (*q) { | |
124 | |
125 //uint32_t ql = tolower(*q); | |
126 | |
127 h ^= ((h << L) + (h >> R) + *q); | |
128 | |
129 q ++; | |
130 | |
131 } | |
132 | |
133 | |
134 | |
135 // add style | |
136 | |
137 h = _rotl(h, 3) ^ style; | |
138 | |
139 | |
140 | |
141 return h; | |
142 | |
143 } | |
144 | |
145 | |
146 | |
147 static SkTypeface::Style GetFontStyle(const LOGFONT& lf) { | |
148 | |
149 int style = SkTypeface::kNormal; | |
150 | |
151 if (lf.lfWeight == FW_SEMIBOLD || lf.lfWeight == FW_DEMIBOLD || lf.lfWeight
== FW_BOLD) | |
152 | |
153 style |= SkTypeface::kBold; | |
154 | |
155 if (lf.lfItalic) | |
156 | |
157 style |= SkTypeface::kItalic; | |
158 | |
159 | |
160 | |
161 return (SkTypeface::Style)style; | |
162 | |
163 } | |
164 | |
165 | |
166 | |
167 struct SkFaceRec { | |
168 | |
169 SkFaceRec* fNext; | |
170 | |
171 uint32_t fRefCnt; | |
172 | |
173 uint32_t fFontID; // checksum of fFace | |
174 | |
175 LOGFONT fFace; | |
176 | |
177 | |
178 | |
179 SkFaceRec() : fFontID(-1), fRefCnt(0) { | |
180 | |
181 memset(&fFace, 0, sizeof(LOGFONT)); | |
182 | |
183 } | |
184 | |
185 ~SkFaceRec() {} | |
186 | |
187 | |
188 | |
189 uint32_t ref() { | |
190 | |
191 return ++fRefCnt; | |
192 | |
193 } | |
194 | |
195 }; | |
196 | |
197 | |
198 | |
199 // Font Face list | |
200 | |
201 static SkFaceRec* gFaceRecHead = NULL; | |
202 | |
203 | |
204 | |
205 static SkFaceRec* find_ft_face(uint32_t fontID) { | |
206 | |
207 SkFaceRec* rec = gFaceRecHead; | |
208 | |
209 while (rec) { | |
210 | |
211 if (rec->fFontID == fontID) { | |
212 | |
213 return rec; | |
214 | |
215 } | |
216 | |
217 rec = rec->fNext; | |
218 | |
219 } | |
220 | |
221 | |
222 | |
223 return NULL; | |
224 | |
225 } | |
226 | |
227 | |
228 | |
229 static SkFaceRec* insert_ft_face(const LOGFONT& lf) { | |
230 | |
231 // need a const char* | |
232 | |
233 uint32_t id = FontFaceChecksum(&(lf.lfFaceName[0]), GetFontStyle(lf)); | |
234 | |
235 SkFaceRec* rec = find_ft_face(id); | |
236 | |
237 if (rec) { | |
238 | |
239 return rec; // found? | |
240 | |
241 } | |
242 | |
243 | |
244 | |
245 rec = SkNEW(SkFaceRec); | |
246 | |
247 rec->fFontID = id; | |
248 | |
249 memcpy(&(rec->fFace), &lf, sizeof(LOGFONT)); | |
250 | |
251 rec->fNext = gFaceRecHead; | |
252 | |
253 gFaceRecHead = rec; | |
254 | |
255 | |
256 | |
257 return rec; | |
258 | |
259 } | |
260 | |
261 | |
262 | |
263 static void unref_ft_face(uint32_t fontID) { | |
264 | |
265 | |
266 | |
267 SkFaceRec* rec = gFaceRecHead; | |
268 | |
269 SkFaceRec* prev = NULL; | |
270 | |
271 while (rec) { | |
272 | |
273 SkFaceRec* next = rec->fNext; | |
274 | |
275 if (rec->fFontID == fontID) { | |
276 | |
277 if (--rec->fRefCnt == 0) { | |
278 | |
279 if (prev) | |
280 | |
281 prev->fNext = next; | |
282 | |
283 else | |
284 | |
285 gFaceRecHead = next; | |
286 | |
287 | |
288 | |
289 SkDELETE(rec); | |
290 | |
291 } | |
292 | |
293 return; | |
294 | |
295 } | |
296 | |
297 prev = rec; | |
298 | |
299 rec = next; | |
300 | |
301 } | |
302 | |
303 SkASSERT("shouldn't get here, face not in list"); | |
304 | |
305 } | |
306 | |
307 | |
308 | |
309 // have to do this because SkTypeface::SkTypeface() is protected | |
310 | |
311 class FontFaceRec_Typeface : public SkTypeface { | |
312 | |
313 public: | |
314 | |
315 | |
316 | |
317 FontFaceRec_Typeface(Style style, uint32_t id) : SkTypeface(style, id) {}; | |
318 | |
319 | |
320 | |
321 virtual ~FontFaceRec_Typeface() {}; | |
322 | |
323 }; | |
324 | |
325 | |
326 | |
327 static const LOGFONT* get_default_font() { | |
328 | |
329 // don't hardcode on Windows, Win2000, XP, Vista, and international all have
different default | |
330 | |
331 // and the user could change too | |
332 | |
333 | |
334 | |
335 if (gDefaultFont.lfFaceName[0] != 0) { | |
336 | |
337 return &gDefaultFont; | |
338 | |
339 } | |
340 | |
341 | |
342 | |
343 NONCLIENTMETRICS ncm; | |
344 | |
345 ncm.cbSize = sizeof(NONCLIENTMETRICS); | |
346 | |
347 SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(ncm), &ncm, 0); | |
348 | |
349 | |
350 | |
351 memcpy(&gDefaultFont, &(ncm.lfMessageFont), sizeof(LOGFONT)); | |
352 | |
353 | |
354 | |
355 return &gDefaultFont; | |
356 | |
357 } | |
358 | |
359 | |
360 | |
361 static SkTypeface* CreateTypeface_(const LOGFONT& lf) { | |
362 | |
363 | |
364 | |
365 SkTypeface::Style style = GetFontStyle(lf); | |
366 | |
367 FontFaceRec_Typeface* ptypeface = new FontFaceRec_Typeface(style, FontFaceCh
ecksum(lf.lfFaceName, style)); | |
368 | |
369 | |
370 | |
371 if (NULL == ptypeface) { | |
372 | |
373 SkASSERT(false); | |
374 | |
375 return NULL; | |
376 | |
377 } | |
378 | |
379 | |
380 | |
381 SkFaceRec* rec = insert_ft_face(lf); | |
382 | |
383 SkASSERT(rec); | |
384 | |
385 | |
386 | |
387 return ptypeface; | |
388 | |
389 } | |
390 | |
391 | |
392 | |
393 class SkScalerContext_Windows : public SkScalerContext { | |
394 | |
395 public: | |
396 | |
397 SkScalerContext_Windows(const SkDescriptor* desc); | |
398 | |
399 virtual ~SkScalerContext_Windows(); | |
400 | |
401 | |
402 | |
403 protected: | |
404 | |
405 virtual unsigned generateGlyphCount() const; | |
406 | |
407 virtual uint16_t generateCharToGlyph(SkUnichar uni); | |
408 | |
409 virtual void generateAdvance(SkGlyph* glyph); | |
410 | |
411 virtual void generateMetrics(SkGlyph* glyph); | |
412 | |
413 virtual void generateImage(const SkGlyph& glyph); | |
414 | |
415 virtual void generatePath(const SkGlyph& glyph, SkPath* path); | |
416 | |
417 virtual void generateLineHeight(SkPoint* ascent, SkPoint* descent); | |
418 | |
419 virtual void generateFontMetrics(SkPaint::FontMetrics* mX, SkPaint::FontMetr
ics* mY); | |
420 | |
421 //virtual SkDeviceContext getDC() {return ddc;} | |
422 | |
423 private: | |
424 | |
425 uint32_t fFontID; | |
426 | |
427 LOGFONT lf; | |
428 | |
429 MAT2 mat22; | |
430 | |
431 HDC ddc; | |
432 | |
433 HFONT savefont; | |
434 | |
435 HFONT font; | |
436 | |
437 }; | |
438 | |
439 | |
440 | |
441 SkScalerContext_Windows::SkScalerContext_Windows(const SkDescriptor* desc) : SkS
calerContext(desc), ddc(0), font(0), savefont(0) { | |
442 | |
443 SkAutoMutexAcquire ac(gFTMutex); | |
444 | |
445 | |
446 | |
447 fFontID = fRec.fFontID; | |
448 | |
449 SkFaceRec* rec = find_ft_face(fRec.fFontID); | |
450 | |
451 if (rec) { | |
452 | |
453 rec->ref(); | |
454 | |
455 memcpy(&lf, &(rec->fFace), sizeof(LOGFONT)); | |
456 | |
457 } | |
458 | |
459 else { | |
460 | |
461 SkASSERT(false); | |
462 | |
463 memcpy(&lf, &gDefaultFont, sizeof(LOGFONT)); | |
464 | |
465 } | |
466 | |
467 | |
468 | |
469 mat22.eM11 = SkScalarToFIXED(fRec.fPost2x2[0][0]); | |
470 | |
471 mat22.eM12 = SkScalarToFIXED(-fRec.fPost2x2[0][1]); | |
472 | |
473 mat22.eM21 = SkScalarToFIXED(fRec.fPost2x2[1][0]); | |
474 | |
475 mat22.eM22 = SkScalarToFIXED(-fRec.fPost2x2[1][1]); | |
476 | |
477 | |
478 | |
479 ddc = ::CreateCompatibleDC(NULL); | |
480 | |
481 SetBkMode(ddc, TRANSPARENT); | |
482 | |
483 | |
484 | |
485 lf.lfHeight = SkScalarFloor(fRec.fTextSize); | |
486 | |
487 font = CreateFontIndirect(&lf); | |
488 | |
489 savefont = (HFONT)SelectObject(ddc, font); | |
490 | |
491 } | |
492 | |
493 | |
494 | |
495 SkScalerContext_Windows::~SkScalerContext_Windows() { | |
496 | |
497 unref_ft_face(fFontID); | |
498 | |
499 | |
500 | |
501 if (ddc) { | |
502 | |
503 ::SelectObject(ddc, savefont); | |
504 | |
505 ::DeleteDC(ddc); | |
506 | |
507 ddc = NULL; | |
508 | |
509 } | |
510 | |
511 if (font) { | |
512 | |
513 ::DeleteObject(font); | |
514 | |
515 } | |
516 | |
517 } | |
518 | |
519 | |
520 | |
521 unsigned SkScalerContext_Windows::generateGlyphCount() const { | |
522 | |
523 return 0xFFFF; | |
524 | |
525 // return fFace->num_glyphs; | |
526 | |
527 } | |
528 | |
529 | |
530 | |
531 uint16_t SkScalerContext_Windows::generateCharToGlyph(SkUnichar uni) { | |
532 | |
533 | |
534 | |
535 //uint16_t index = 0; | |
536 | |
537 //GetGlyphIndicesW(ddc, &(uint16_t&)uni, 1, &index, 0); | |
538 | |
539 //return index; | |
540 | |
541 | |
542 | |
543 // let's just use the uni as index on Windows | |
544 | |
545 return SkToU16(uni); | |
546 | |
547 } | |
548 | |
549 | |
550 | |
551 void SkScalerContext_Windows::generateAdvance(SkGlyph* glyph) { | |
552 | |
553 this->generateMetrics(glyph); | |
554 | |
555 } | |
556 | |
557 | |
558 | |
559 void SkScalerContext_Windows::generateMetrics(SkGlyph* glyph) { | |
560 | |
561 | |
562 | |
563 SkASSERT(ddc); | |
564 | |
565 | |
566 | |
567 GLYPHMETRICS gm; | |
568 | |
569 memset(&gm, 0, sizeof(gm)); | |
570 | |
571 | |
572 | |
573 glyph->fRsbDelta = 0; | |
574 | |
575 glyph->fLsbDelta = 0; | |
576 | |
577 | |
578 | |
579 UINT glyphIndexFlag = 0; //glyph->fIsCodePoint ? 0 : GGO_GLYPH_INDEX; | |
580 | |
581 // UINT glyphIndexFlag = GGO_GLYPH_INDEX; | |
582 | |
583 // Note: need to use GGO_GRAY8_BITMAP instead of GGO_METRICS because GGO_MET
RICS returns a smaller | |
584 | |
585 // BlackBlox; we need the bigger one in case we need the image. fAdvance is
the same. | |
586 | |
587 uint32_t ret = GetGlyphOutlineW(ddc, glyph->getGlyphID(0), GGO_GRAY8_BITMAP
| glyphIndexFlag, &gm, 0, NULL, &mat22); | |
588 | |
589 | |
590 | |
591 if (GDI_ERROR != ret) { | |
592 | |
593 if (ret == 0) { | |
594 | |
595 // for white space, ret is zero and gmBlackBoxX, gmBlackBoxY are 1 i
ncorrectly! | |
596 | |
597 gm.gmBlackBoxX = gm.gmBlackBoxY = 0; | |
598 | |
599 } | |
600 | |
601 glyph->fWidth = gm.gmBlackBoxX; | |
602 | |
603 glyph->fHeight = gm.gmBlackBoxY; | |
604 | |
605 glyph->fTop = SkToS16(gm.gmptGlyphOrigin.y - gm.gmBlackBoxY); | |
606 | |
607 glyph->fLeft = SkToS16(gm.gmptGlyphOrigin.x); | |
608 | |
609 glyph->fAdvanceX = SkIntToFixed(gm.gmCellIncX); | |
610 | |
611 glyph->fAdvanceY = -SkIntToFixed(gm.gmCellIncY); | |
612 | |
613 } else { | |
614 | |
615 glyph->fWidth = 0; | |
616 | |
617 } | |
618 | |
619 | |
620 | |
621 #if 0 | |
622 | |
623 char buf[1024]; | |
624 | |
625 sprintf(buf, "generateMetrics: id:%d, w=%d, h=%d, font:%s, fh:%d\n", glyph->
fID, glyph->fWidth, glyph->fHeight, lf.lfFaceName, lf.lfHeight); | |
626 | |
627 OutputDebugString(buf); | |
628 | |
629 #endif | |
630 | |
631 } | |
632 | |
633 | |
634 | |
635 void SkScalerContext_Windows::generateFontMetrics(SkPaint::FontMetrics* mx, SkPa
int::FontMetrics* my) { | |
636 | |
637 //SkASSERT(false); | |
638 | |
639 if (mx) | |
640 | |
641 memset(mx, 0, sizeof(SkPaint::FontMetrics)); | |
642 | |
643 if (my) | |
644 | |
645 memset(my, 0, sizeof(SkPaint::FontMetrics)); | |
646 | |
647 return; | |
648 | |
649 } | |
650 | |
651 | |
652 | |
653 void SkScalerContext_Windows::generateImage(const SkGlyph& glyph) { | |
654 | |
655 | |
656 | |
657 SkAutoMutexAcquire ac(gFTMutex); | |
658 | |
659 | |
660 | |
661 SkASSERT(ddc); | |
662 | |
663 | |
664 | |
665 GLYPHMETRICS gm; | |
666 | |
667 memset(&gm, 0, sizeof(gm)); | |
668 | |
669 | |
670 | |
671 #if 0 | |
672 | |
673 char buf[1024]; | |
674 | |
675 sprintf(buf, "generateImage: id:%d, w=%d, h=%d, font:%s,fh:%d\n", glyph.fID,
glyph.fWidth, glyph.fHeight, lf.lfFaceName, lf.lfHeight); | |
676 | |
677 OutputDebugString(buf); | |
678 | |
679 #endif | |
680 | |
681 | |
682 | |
683 uint32_t bytecount = 0; | |
684 | |
685 UINT glyphIndexFlag = 0; //glyph.fIsCodePoint ? 0 : GGO_GLYPH_INDEX; | |
686 | |
687 // UINT glyphIndexFlag = GGO_GLYPH_INDEX; | |
688 | |
689 uint32_t total_size = GetGlyphOutlineW(ddc, glyph.fID, GGO_GRAY8_BITMAP | gl
yphIndexFlag, &gm, 0, NULL, &mat22); | |
690 | |
691 if (GDI_ERROR != total_size && total_size > 0) { | |
692 | |
693 uint8_t *pBuff = new uint8_t[total_size]; | |
694 | |
695 if (NULL != pBuff) { | |
696 | |
697 total_size = GetGlyphOutlineW(ddc, glyph.fID, GGO_GRAY8_BITMAP | gly
phIndexFlag, &gm, total_size, pBuff, &mat22); | |
698 | |
699 | |
700 | |
701 SkASSERT(total_size != GDI_ERROR); | |
702 | |
703 | |
704 | |
705 SkASSERT(glyph.fWidth == gm.gmBlackBoxX); | |
706 | |
707 SkASSERT(glyph.fHeight == gm.gmBlackBoxY); | |
708 | |
709 | |
710 | |
711 uint8_t* dst = (uint8_t*)glyph.fImage; | |
712 | |
713 uint32_t pitch = (gm.gmBlackBoxX + 3) & ~0x3; | |
714 | |
715 if (pitch != glyph.rowBytes()) { | |
716 | |
717 SkASSERT(false); // glyph.fImage has different rowsize!? | |
718 | |
719 } | |
720 | |
721 | |
722 | |
723 for (int32_t y = gm.gmBlackBoxY - 1; y >= 0; y--) { | |
724 | |
725 uint8_t* src = pBuff + pitch * y; | |
726 | |
727 | |
728 | |
729 for (uint32_t x = 0; x < gm.gmBlackBoxX; x++) { | |
730 | |
731 if (*src > 63) { | |
732 | |
733 *dst = 0xFF; | |
734 | |
735 } | |
736 | |
737 else { | |
738 | |
739 *dst = *src << 2; // scale to 0-255 | |
740 | |
741 } | |
742 | |
743 dst++; | |
744 | |
745 src++; | |
746 | |
747 bytecount++; | |
748 | |
749 } | |
750 | |
751 memset(dst, 0, glyph.rowBytes() - glyph.fWidth); | |
752 | |
753 dst += glyph.rowBytes() - glyph.fWidth; | |
754 | |
755 } | |
756 | |
757 | |
758 | |
759 delete[] pBuff; | |
760 | |
761 } | |
762 | |
763 } | |
764 | |
765 | |
766 | |
767 SkASSERT(GDI_ERROR != total_size && total_size >= 0); | |
768 | |
769 | |
770 | |
771 } | |
772 | |
773 | |
774 | |
775 void SkScalerContext_Windows::generatePath(const SkGlyph& glyph, SkPath* path) { | |
776 | |
777 | |
778 | |
779 SkAutoMutexAcquire ac(gFTMutex); | |
780 | |
781 | |
782 | |
783 SkASSERT(&glyph && path); | |
784 | |
785 SkASSERT(ddc); | |
786 | |
787 | |
788 | |
789 path->reset(); | |
790 | |
791 | |
792 | |
793 #if 0 | |
794 | |
795 char buf[1024]; | |
796 | |
797 sprintf(buf, "generatePath: id:%d, w=%d, h=%d, font:%s,fh:%d\n", glyph.fID,
glyph.fWidth, glyph.fHeight, lf.lfFaceName, lf.lfHeight); | |
798 | |
799 OutputDebugString(buf); | |
800 | |
801 #endif | |
802 | |
803 | |
804 | |
805 GLYPHMETRICS gm; | |
806 | |
807 UINT glyphIndexFlag = 0; //glyph.fIsCodePoint ? 0 : GGO_GLYPH_INDEX; | |
808 | |
809 uint32_t total_size = GetGlyphOutlineW(ddc, glyph.fID, GGO_NATIVE | glyphInd
exFlag, &gm, BUFFERSIZE, glyphbuf, &mat22); | |
810 | |
811 | |
812 | |
813 if (GDI_ERROR != total_size) { | |
814 | |
815 | |
816 | |
817 const uint8_t* cur_glyph = glyphbuf; | |
818 | |
819 const uint8_t* end_glyph = glyphbuf + total_size; | |
820 | |
821 | |
822 | |
823 while(cur_glyph < end_glyph) { | |
824 | |
825 const TTPOLYGONHEADER* th = (TTPOLYGONHEADER*)cur_glyph; | |
826 | |
827 | |
828 | |
829 const uint8_t* end_poly = cur_glyph + th->cb; | |
830 | |
831 const uint8_t* cur_poly = cur_glyph + sizeof(TTPOLYGONHEADER); | |
832 | |
833 | |
834 | |
835 path->moveTo(SkFixedToScalar(*(SkFixed*)(&th->pfxStart.x)), SkFixedT
oScalar(*(SkFixed*)(&th->pfxStart.y))); | |
836 | |
837 | |
838 | |
839 while(cur_poly < end_poly) { | |
840 | |
841 const TTPOLYCURVE* pc = (const TTPOLYCURVE*)cur_poly; | |
842 | |
843 | |
844 | |
845 if (pc->wType == TT_PRIM_LINE) { | |
846 | |
847 for (uint16_t i = 0; i < pc->cpfx; i++) { | |
848 | |
849 path->lineTo(SkFixedToScalar(*(SkFixed*)(&pc->apfx[i].x)
), SkFixedToScalar(*(SkFixed*)(&pc->apfx[i].y))); | |
850 | |
851 } | |
852 | |
853 } | |
854 | |
855 | |
856 | |
857 if (pc->wType == TT_PRIM_QSPLINE) { | |
858 | |
859 for (uint16_t u = 0; u < pc->cpfx - 1; u++) { // Walk throug
h points in spline | |
860 | |
861 POINTFX pnt_b = pc->apfx[u]; // B is always the curre
nt point | |
862 | |
863 POINTFX pnt_c = pc->apfx[u+1]; | |
864 | |
865 | |
866 | |
867 if (u < pc->cpfx - 2) { // If not on last splin
e, compute C | |
868 | |
869 pnt_c.x = SkFixedToFIXED(SkFixedAve(*(SkFixed*)(&pnt
_b.x), *(SkFixed*)(&pnt_c.x))); | |
870 | |
871 pnt_c.y = SkFixedToFIXED(SkFixedAve(*(SkFixed*)(&pnt
_b.y), *(SkFixed*)(&pnt_c.y))); | |
872 | |
873 } | |
874 | |
875 | |
876 | |
877 path->quadTo(SkFixedToScalar(*(SkFixed*)(&pnt_b.x)), SkF
ixedToScalar(*(SkFixed*)(&pnt_b.y)), SkFixedToScalar(*(SkFixed*)(&pnt_c.x)), SkF
ixedToScalar(*(SkFixed*)(&pnt_c.y))); | |
878 | |
879 } | |
880 | |
881 } | |
882 | |
883 cur_poly += sizeof(uint16_t) * 2 + sizeof(POINTFX) * pc->cpfx; | |
884 | |
885 } | |
886 | |
887 cur_glyph += th->cb; | |
888 | |
889 path->close(); | |
890 | |
891 } | |
892 | |
893 } | |
894 | |
895 else { | |
896 | |
897 SkASSERT(false); | |
898 | |
899 } | |
900 | |
901 //char buf[1024]; | |
902 | |
903 //sprintf(buf, "generatePath: count:%d\n", count); | |
904 | |
905 //OutputDebugString(buf); | |
906 | |
907 } | |
908 | |
909 | |
910 | |
911 | |
912 | |
913 // Note: not sure this is the correct implementation | |
914 | |
915 void SkScalerContext_Windows::generateLineHeight(SkPoint* ascent, SkPoint* desce
nt) { | |
916 | |
917 | |
918 | |
919 SkASSERT(ddc); | |
920 | |
921 | |
922 | |
923 OUTLINETEXTMETRIC otm; | |
924 | |
925 | |
926 | |
927 uint32_t ret = GetOutlineTextMetrics(ddc, sizeof(otm), &otm); | |
928 | |
929 | |
930 | |
931 if (sizeof(otm) == ret) { | |
932 | |
933 if (ascent) | |
934 | |
935 ascent->iset(0, otm.otmAscent); | |
936 | |
937 if (descent) | |
938 | |
939 descent->iset(0, otm.otmDescent); | |
940 | |
941 } | |
942 | |
943 | |
944 | |
945 return; | |
946 | |
947 } | |
948 | |
949 | |
950 | |
951 void SkFontHost::Serialize(const SkTypeface* face, SkWStream* stream) { | |
952 | |
953 SkASSERT(!"SkFontHost::Serialize unimplemented"); | |
954 | |
955 } | |
956 | |
957 | |
958 | |
959 SkTypeface* SkFontHost::Deserialize(SkStream* stream) { | |
960 | |
961 SkASSERT(!"SkFontHost::Deserialize unimplemented"); | |
962 | |
963 return NULL; | |
964 | |
965 } | |
966 | |
967 | |
968 | |
969 SkTypeface* SkFontHost::CreateTypeface(SkStream* stream) { | |
970 | |
971 | |
972 | |
973 //Should not be used on Windows, keep linker happy | |
974 | |
975 SkASSERT(false); | |
976 | |
977 get_default_font(); | |
978 | |
979 return CreateTypeface_(gDefaultFont); | |
980 | |
981 } | |
982 | |
983 | |
984 | |
985 SkScalerContext* SkFontHost::CreateScalerContext(const SkDescriptor* desc) { | |
986 | |
987 return SkNEW_ARGS(SkScalerContext_Windows, (desc)); | |
988 | |
989 } | |
990 | |
991 | |
992 | |
993 SkScalerContext* SkFontHost::CreateFallbackScalerContext(const SkScalerContext::
Rec& rec) { | |
994 | |
995 get_default_font(); | |
996 | |
997 | |
998 | |
999 SkAutoDescriptor ad(sizeof(rec) + sizeof(gDefaultFont) + SkDescriptor::Co
mputeOverhead(2)); | |
1000 | |
1001 SkDescriptor* desc = ad.getDesc(); | |
1002 | |
1003 | |
1004 | |
1005 desc->init(); | |
1006 | |
1007 SkScalerContext::Rec* newRec = | |
1008 | |
1009 (SkScalerContext::Rec*)desc->addEntry(kRec_SkDescriptorTag, sizeof(rec), &re
c); | |
1010 | |
1011 | |
1012 | |
1013 get_default_font(); | |
1014 | |
1015 CreateTypeface_(gDefaultFont); | |
1016 | |
1017 newRec->fFontID = FontFaceChecksum(gDefaultFont.lfFaceName, GetFontStyle(gDe
faultFont)); | |
1018 | |
1019 desc->computeChecksum(); | |
1020 | |
1021 | |
1022 | |
1023 return SkFontHost::CreateScalerContext(desc); | |
1024 | |
1025 } | |
1026 | |
1027 | |
1028 | |
1029 /** Return the closest matching typeface given either an existing family | |
1030 | |
1031 (specified by a typeface in that family) or by a familyName, and a | |
1032 | |
1033 requested style. | |
1034 | |
1035 1) If familyFace is null, use famillyName. | |
1036 | |
1037 2) If famillyName is null, use familyFace. | |
1038 | |
1039 3) If both are null, return the default font that best matches style | |
1040 | |
1041 This MUST not return NULL. | |
1042 | |
1043 */ | |
1044 | |
1045 | |
1046 | |
1047 SkTypeface* SkFontHost::FindTypeface(const SkTypeface* familyFace, const char fa
milyName[], SkTypeface::Style style) { | |
1048 | |
1049 | |
1050 | |
1051 SkAutoMutexAcquire ac(gFTMutex); | |
1052 | |
1053 | |
1054 | |
1055 #ifndef CAN_USE_LOGFONT_NAME | |
1056 | |
1057 familyName = NULL; | |
1058 | |
1059 familyFace = NULL; | |
1060 | |
1061 #endif | |
1062 | |
1063 | |
1064 | |
1065 // clip to legal style bits | |
1066 | |
1067 style = (SkTypeface::Style)(style & SkTypeface::kBoldItalic); | |
1068 | |
1069 | |
1070 | |
1071 SkTypeface* tf = NULL; | |
1072 | |
1073 if (NULL == familyFace && NULL == familyName) { | |
1074 | |
1075 LOGFONT lf; | |
1076 | |
1077 get_default_font(); | |
1078 | |
1079 memcpy(&lf, &gDefaultFont, sizeof(LOGFONT)); | |
1080 | |
1081 lf.lfWeight = (style & SkTypeface::kBold) != 0 ? FW_BOLD : FW_NORMAL ; | |
1082 | |
1083 lf.lfItalic = ((style & SkTypeface::kItalic) != 0); | |
1084 | |
1085 tf = CreateTypeface_(lf); | |
1086 | |
1087 } else { | |
1088 | |
1089 #ifdef CAN_USE_LOGFONT_NAME | |
1090 | |
1091 LOGFONT lf; | |
1092 | |
1093 if (NULL != familyFace) { | |
1094 | |
1095 uint32_t id = familyFace->uniqueID(); | |
1096 | |
1097 SkFaceRec* rec = find_ft_face(id); | |
1098 | |
1099 if (!rec) { | |
1100 | |
1101 SkASSERT(false); | |
1102 | |
1103 get_default_font(); | |
1104 | |
1105 memcpy(&lf, &gDefaultFont, sizeof(LOGFONT)); | |
1106 | |
1107 } | |
1108 | |
1109 else { | |
1110 | |
1111 memcpy(&lf, &(rec->fFace), sizeof(LOGFONT)); | |
1112 | |
1113 } | |
1114 | |
1115 } | |
1116 | |
1117 else { | |
1118 | |
1119 memset(&lf, 0, sizeof(LOGFONT)); | |
1120 | |
1121 | |
1122 | |
1123 lf.lfHeight = -11; // default | |
1124 | |
1125 lf.lfQuality = PROOF_QUALITY; | |
1126 | |
1127 lf.lfCharSet = DEFAULT_CHARSET; | |
1128 | |
1129 | |
1130 | |
1131 _tcsncpy(lf.lfFaceName, familyName, LF_FACESIZE); | |
1132 | |
1133 lf.lfFaceName[LF_FACESIZE-1] = '\0'; | |
1134 | |
1135 } | |
1136 | |
1137 | |
1138 | |
1139 // use the style desired | |
1140 | |
1141 lf.lfWeight = (style & SkTypeface::kBold) != 0 ? FW_BOLD : FW_NORMAL ; | |
1142 | |
1143 lf.lfItalic = ((style & SkTypeface::kItalic) != 0); | |
1144 | |
1145 tf = CreateTypeface_(lf); | |
1146 | |
1147 #endif | |
1148 | |
1149 } | |
1150 | |
1151 | |
1152 | |
1153 if (NULL == tf) { | |
1154 | |
1155 get_default_font(); | |
1156 | |
1157 tf = CreateTypeface_(gDefaultFont); | |
1158 | |
1159 } | |
1160 | |
1161 return tf; | |
1162 | |
1163 } | |
1164 | |
1165 | |
1166 | |
1167 size_t SkFontHost::ShouldPurgeFontCache(size_t sizeAllocatedSoFar) { | |
1168 | |
1169 if (sizeAllocatedSoFar > FONT_CACHE_MEMORY_BUDGET) | |
1170 | |
1171 return sizeAllocatedSoFar - FONT_CACHE_MEMORY_BUDGET; | |
1172 | |
1173 else | |
1174 | |
1175 return 0; // nothing to do | |
1176 | |
1177 } | |
1178 | |
1179 | |
1180 | |
1181 int SkFontHost::ComputeGammaFlag(const SkPaint& paint) { | |
1182 | |
1183 return 0; | |
1184 | |
1185 } | |
1186 | |
1187 | |
1188 | |
1189 void SkFontHost::GetGammaTables(const uint8_t* tables[2]) { | |
1190 | |
1191 tables[0] = NULL; // black gamma (e.g. exp=1.4) | |
1192 | |
1193 tables[1] = NULL; // white gamma (e.g. exp= 1/1.4) | |
1194 | |
1195 } | |
1196 | |
1197 | |
1198 | |
1199 #endif // WIN32 | |
1200 | |
1201 | |
1202 | |
OLD | NEW |