Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: src/ports/SkFontHost_FreeType.cpp

Issue 107863002: [PDF] Fix font embedding restrictions. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2006 The Android Open Source Project 3 * Copyright 2006 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 #else 404 #else
405 // No embedding is 0x2 and bitmap embedding only is 0x200. 405 // No embedding is 0x2 and bitmap embedding only is 0x200.
406 TT_OS2* os2_table; 406 TT_OS2* os2_table;
407 if ((os2_table = (TT_OS2*)FT_Get_Sfnt_Table(face, ft_sfnt_os2)) != NULL) { 407 if ((os2_table = (TT_OS2*)FT_Get_Sfnt_Table(face, ft_sfnt_os2)) != NULL) {
408 return (os2_table->fsType & 0x202) == 0; 408 return (os2_table->fsType & 0x202) == 0;
409 } 409 }
410 return false; // We tried, fail safe. 410 return false; // We tried, fail safe.
411 #endif 411 #endif
412 } 412 }
413 413
414 static bool canSubset(FT_Face face) {
415 #ifdef FT_FSTYPE_NO_SUBSETTING
416 FT_UShort fsType = FT_Get_FSType_Flags(face);
417 return (fsType & FT_FSTYPE_NO_SUBSETTING) == 0;
418 #else
419 // No subset is 0x100.
420 TT_OS2* os2_table;
421 if ((os2_table = (TT_OS2*)FT_Get_Sfnt_Table(face, ft_sfnt_os2)) != NULL) {
422 return (os2_table->fsType & 0x100) == 0;
423 }
424 return false; // We tried, fail safe.
425 #endif
426 }
427
414 static bool GetLetterCBox(FT_Face face, char letter, FT_BBox* bbox) { 428 static bool GetLetterCBox(FT_Face face, char letter, FT_BBox* bbox) {
415 const FT_UInt glyph_id = FT_Get_Char_Index(face, letter); 429 const FT_UInt glyph_id = FT_Get_Char_Index(face, letter);
416 if (!glyph_id) 430 if (!glyph_id)
417 return false; 431 return false;
418 FT_Load_Glyph(face, glyph_id, FT_LOAD_NO_SCALE); 432 FT_Load_Glyph(face, glyph_id, FT_LOAD_NO_SCALE);
419 FT_Outline_Get_CBox(&face->glyph->outline, bbox); 433 FT_Outline_Get_CBox(&face->glyph->outline, bbox);
420 return true; 434 return true;
421 } 435 }
422 436
423 static bool getWidthAdvance(FT_Face face, int gId, int16_t* data) { 437 static bool getWidthAdvance(FT_Face face, int gId, int16_t* data) {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 return NULL; 502 return NULL;
489 #else 503 #else
490 AutoFTAccess fta(this); 504 AutoFTAccess fta(this);
491 FT_Face face = fta.face(); 505 FT_Face face = fta.face();
492 if (!face) { 506 if (!face) {
493 return NULL; 507 return NULL;
494 } 508 }
495 509
496 SkAdvancedTypefaceMetrics* info = new SkAdvancedTypefaceMetrics; 510 SkAdvancedTypefaceMetrics* info = new SkAdvancedTypefaceMetrics;
497 info->fFontName.set(FT_Get_Postscript_Name(face)); 511 info->fFontName.set(FT_Get_Postscript_Name(face));
498 info->fMultiMaster = FT_HAS_MULTIPLE_MASTERS(face); 512 info->fFlags = SkAdvancedTypefaceMetrics::kEmpty_Flag;
513 if (FT_HAS_MULTIPLE_MASTERS(face)) {
514 info->fFlags = SkTBitOr<SkAdvancedTypefaceMetrics::FontFlags>(
515 info->fFlags, SkAdvancedTypefaceMetrics::kMultiMaster_Flag);
516 }
517 if (!canEmbed(face)) {
518 info->fFlags = SkTBitOr<SkAdvancedTypefaceMetrics::FontFlags>(
519 info->fFlags, SkAdvancedTypefaceMetrics::kNotEmbeddable_Flag);
520 }
521 if (!canSubset(face)) {
522 info->fFlags = SkTBitOr<SkAdvancedTypefaceMetrics::FontFlags>(
523 info->fFlags, SkAdvancedTypefaceMetrics::kNotSubsettable_Flag);
524 }
499 info->fLastGlyphID = face->num_glyphs - 1; 525 info->fLastGlyphID = face->num_glyphs - 1;
500 info->fEmSize = 1000; 526 info->fEmSize = 1000;
501 527
502 bool cid = false; 528 bool cid = false;
503 const char* fontType = FT_Get_X11_Font_Format(face); 529 const char* fontType = FT_Get_X11_Font_Format(face);
504 if (strcmp(fontType, "Type 1") == 0) { 530 if (strcmp(fontType, "Type 1") == 0) {
505 info->fType = SkAdvancedTypefaceMetrics::kType1_Font; 531 info->fType = SkAdvancedTypefaceMetrics::kType1_Font;
506 } else if (strcmp(fontType, "CID Type 1") == 0) { 532 } else if (strcmp(fontType, "CID Type 1") == 0) {
507 info->fType = SkAdvancedTypefaceMetrics::kType1CID_Font; 533 info->fType = SkAdvancedTypefaceMetrics::kType1CID_Font;
508 cid = true; 534 cid = true;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 } else if (got_m && !got_x) { 607 } else if (got_m && !got_x) {
582 info->fCapHeight = m_bbox.yMax - m_bbox.yMin; 608 info->fCapHeight = m_bbox.yMax - m_bbox.yMin;
583 } else if (!got_m && got_x) { 609 } else if (!got_m && got_x) {
584 info->fCapHeight = x_bbox.yMax - x_bbox.yMin; 610 info->fCapHeight = x_bbox.yMax - x_bbox.yMin;
585 } 611 }
586 } 612 }
587 613
588 info->fBBox = SkIRect::MakeLTRB(face->bbox.xMin, face->bbox.yMax, 614 info->fBBox = SkIRect::MakeLTRB(face->bbox.xMin, face->bbox.yMax,
589 face->bbox.xMax, face->bbox.yMin); 615 face->bbox.xMax, face->bbox.yMin);
590 616
591 if (!canEmbed(face) || !FT_IS_SCALABLE(face) || 617 if (!FT_IS_SCALABLE(face)) {
592 info->fType == SkAdvancedTypefaceMetrics::kOther_Font) {
593 perGlyphInfo = SkAdvancedTypefaceMetrics::kNo_PerGlyphInfo; 618 perGlyphInfo = SkAdvancedTypefaceMetrics::kNo_PerGlyphInfo;
594 } 619 }
595 620
596 if (perGlyphInfo & SkAdvancedTypefaceMetrics::kHAdvance_PerGlyphInfo) { 621 if (perGlyphInfo & SkAdvancedTypefaceMetrics::kHAdvance_PerGlyphInfo) {
597 if (FT_IS_FIXED_WIDTH(face)) { 622 if (FT_IS_FIXED_WIDTH(face)) {
598 appendRange(&info->fGlyphWidths, 0); 623 appendRange(&info->fGlyphWidths, 0);
599 int16_t advance = face->max_advance_width; 624 int16_t advance = face->max_advance_width;
600 info->fGlyphWidths->fAdvance.append(1, &advance); 625 info->fGlyphWidths->fAdvance.append(1, &advance);
601 finishRange(info->fGlyphWidths.get(), 0, 626 finishRange(info->fGlyphWidths.get(), 0,
602 SkAdvancedTypefaceMetrics::WidthRange::kDefault); 627 SkAdvancedTypefaceMetrics::WidthRange::kDefault);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 info->fGlyphNames->get()[gID].set(glyphName); 670 info->fGlyphNames->get()[gID].set(glyphName);
646 } 671 }
647 } 672 }
648 673
649 if (perGlyphInfo & SkAdvancedTypefaceMetrics::kToUnicode_PerGlyphInfo && 674 if (perGlyphInfo & SkAdvancedTypefaceMetrics::kToUnicode_PerGlyphInfo &&
650 info->fType != SkAdvancedTypefaceMetrics::kType1_Font && 675 info->fType != SkAdvancedTypefaceMetrics::kType1_Font &&
651 face->num_charmaps) { 676 face->num_charmaps) {
652 populate_glyph_to_unicode(face, &(info->fGlyphToUnicode)); 677 populate_glyph_to_unicode(face, &(info->fGlyphToUnicode));
653 } 678 }
654 679
655 if (!canEmbed(face))
656 info->fType = SkAdvancedTypefaceMetrics::kNotEmbeddable_Font;
657
658 return info; 680 return info;
659 #endif 681 #endif
660 } 682 }
661 683
662 /////////////////////////////////////////////////////////////////////////// 684 ///////////////////////////////////////////////////////////////////////////
663 685
664 #define BLACK_LUMINANCE_LIMIT 0x40 686 #define BLACK_LUMINANCE_LIMIT 0x40
665 #define WHITE_LUMINANCE_LIMIT 0xA0 687 #define WHITE_LUMINANCE_LIMIT 0xA0
666 688
667 static bool bothZero(SkScalar a, SkScalar b) { 689 static bool bothZero(SkScalar a, SkScalar b) {
(...skipping 855 matching lines...) Expand 10 before | Expand all | Expand 10 after
1523 *style = (SkTypeface::Style) tempStyle; 1545 *style = (SkTypeface::Style) tempStyle;
1524 } 1546 }
1525 if (isFixedPitch) { 1547 if (isFixedPitch) {
1526 *isFixedPitch = FT_IS_FIXED_WIDTH(face); 1548 *isFixedPitch = FT_IS_FIXED_WIDTH(face);
1527 } 1549 }
1528 1550
1529 FT_Done_Face(face); 1551 FT_Done_Face(face);
1530 FT_Done_FreeType(library); 1552 FT_Done_FreeType(library);
1531 return true; 1553 return true;
1532 } 1554 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698