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

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

Issue 685803003: Revert of Extend SkFontMgr_Custom to cover ttc, otf, pfb. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « src/fonts/SkFontMgr_fontconfig.cpp ('k') | src/ports/SkFontHost_FreeType_common.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "SkAdvancedTypefaceMetrics.h" 9 #include "SkAdvancedTypefaceMetrics.h"
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
(...skipping 1651 matching lines...) Expand 10 before | Expand all | Expand 10 after
1662 return 0; 1662 return 0;
1663 } 1663 }
1664 } 1664 }
1665 1665
1666 return size; 1666 return size;
1667 } 1667 }
1668 1668
1669 /////////////////////////////////////////////////////////////////////////////// 1669 ///////////////////////////////////////////////////////////////////////////////
1670 /////////////////////////////////////////////////////////////////////////////// 1670 ///////////////////////////////////////////////////////////////////////////////
1671 1671
1672 1672 #include "SkTSearch.h"
1673 SkTypeface_FreeType::Scanner::Scanner() { 1673 /*static*/ bool SkTypeface_FreeType::ScanFont(
1674 if (FT_Init_FreeType(&fLibrary)) { 1674 SkStream* stream, int ttcIndex, SkString* name, SkFontStyle* style, bool* is FixedPitch)
1675 fLibrary = NULL; 1675 {
1676 } 1676 FT_Library library;
1677 } 1677 if (FT_Init_FreeType(&library)) {
1678 SkTypeface_FreeType::Scanner::~Scanner() { 1678 return false;
1679 FT_Done_FreeType(fLibrary);
1680 }
1681
1682 FT_Face SkTypeface_FreeType::Scanner::openFace(SkStream* stream, int ttcIndex) c onst {
1683 if (fLibrary == NULL) {
1684 return NULL;
1685 } 1679 }
1686 1680
1687 FT_Open_Args args; 1681 FT_Open_Args args;
1688 memset(&args, 0, sizeof(args)); 1682 memset(&args, 0, sizeof(args));
1689 1683
1690 const void* memoryBase = stream->getMemoryBase(); 1684 const void* memoryBase = stream->getMemoryBase();
1691 FT_StreamRec streamRec; 1685 FT_StreamRec streamRec;
1692 1686
1693 if (memoryBase) { 1687 if (memoryBase) {
1694 args.flags = FT_OPEN_MEMORY; 1688 args.flags = FT_OPEN_MEMORY;
1695 args.memory_base = (const FT_Byte*)memoryBase; 1689 args.memory_base = (const FT_Byte*)memoryBase;
1696 args.memory_size = stream->getLength(); 1690 args.memory_size = stream->getLength();
1697 } else { 1691 } else {
1698 memset(&streamRec, 0, sizeof(streamRec)); 1692 memset(&streamRec, 0, sizeof(streamRec));
1699 streamRec.size = stream->getLength(); 1693 streamRec.size = stream->getLength();
1700 streamRec.descriptor.pointer = stream; 1694 streamRec.descriptor.pointer = stream;
1701 streamRec.read = sk_stream_read; 1695 streamRec.read = sk_stream_read;
1702 streamRec.close = sk_stream_close; 1696 streamRec.close = sk_stream_close;
1703 1697
1704 args.flags = FT_OPEN_STREAM; 1698 args.flags = FT_OPEN_STREAM;
1705 args.stream = &streamRec; 1699 args.stream = &streamRec;
1706 } 1700 }
1707 1701
1708 FT_Face face; 1702 FT_Face face;
1709 if (FT_Open_Face(fLibrary, &args, ttcIndex, &face)) { 1703 if (FT_Open_Face(library, &args, ttcIndex, &face)) {
1710 return NULL; 1704 FT_Done_FreeType(library);
1711 }
1712 return face;
1713 }
1714
1715 bool SkTypeface_FreeType::Scanner::recognizedFont(SkStream* stream, int* numFace s) const {
1716 FT_Face face = this->openFace(stream, -1);
1717 if (NULL == face) {
1718 return false; 1705 return false;
1719 } 1706 }
1720 1707
1721 *numFaces = face->num_faces;
1722
1723 FT_Done_Face(face);
1724 return true;
1725 }
1726
1727 #include "SkTSearch.h"
1728 bool SkTypeface_FreeType::Scanner::scanFont(
1729 SkStream* stream, int ttcIndex, SkString* name, SkFontStyle* style, bool* is FixedPitch) const
1730 {
1731 FT_Face face = this->openFace(stream, ttcIndex);
1732 if (NULL == face) {
1733 return false;
1734 }
1735
1736 int weight = SkFontStyle::kNormal_Weight; 1708 int weight = SkFontStyle::kNormal_Weight;
1737 int width = SkFontStyle::kNormal_Width; 1709 int width = SkFontStyle::kNormal_Width;
1738 SkFontStyle::Slant slant = SkFontStyle::kUpright_Slant; 1710 SkFontStyle::Slant slant = SkFontStyle::kUpright_Slant;
1739 if (face->style_flags & FT_STYLE_FLAG_BOLD) { 1711 if (face->style_flags & FT_STYLE_FLAG_BOLD) {
1740 weight = SkFontStyle::kBold_Weight; 1712 weight = SkFontStyle::kBold_Weight;
1741 } 1713 }
1742 if (face->style_flags & FT_STYLE_FLAG_ITALIC) { 1714 if (face->style_flags & FT_STYLE_FLAG_ITALIC) {
1743 slant = SkFontStyle::kItalic_Slant; 1715 slant = SkFontStyle::kItalic_Slant;
1744 } 1716 }
1745 1717
1746 PS_FontInfoRec psFontInfo; 1718 PS_FontInfoRec psFontInfo;
1747 TT_OS2* os2 = static_cast<TT_OS2*>(FT_Get_Sfnt_Table(face, ft_sfnt_os2)); 1719 TT_OS2* os2 = static_cast<TT_OS2*>(FT_Get_Sfnt_Table(face, ft_sfnt_os2));
1748 if (os2 && os2->version != 0xffff) { 1720 if (os2 && os2->version != 0xffff) {
1749 weight = os2->usWeightClass; 1721 weight = os2->usWeightClass;
1750 width = os2->usWidthClass; 1722 width = os2->usWidthClass;
1751 } else if (0 == FT_Get_PS_Font_Info(face, &psFontInfo) && psFontInfo.weight) { 1723 } else if (0 == FT_Get_PS_Font_Info(face, &psFontInfo) && psFontInfo.weight) {
1752 static const struct { 1724 static const struct {
1753 char const * const name; 1725 char const * const name;
1754 int const weight; 1726 int const weight;
1755 } commonWeights [] = { 1727 } commonWeights [] = {
1756 // There are probably more common names, but these are known to exis t. 1728 // There are probably more common names, but these are known to exis t.
1757 { "black", SkFontStyle::kBlack_Weight }, 1729 { "black", SkFontStyle::kBlack_Weight },
1758 { "bold", SkFontStyle::kBold_Weight }, 1730 { "bold", SkFontStyle::kBold_Weight },
1759 { "book", (SkFontStyle::kNormal_Weight + SkFontStyle::kLight_Weight) /2 }, 1731 { "book", (SkFontStyle::kNormal_Weight + SkFontStyle::kLight_Weight) /2 },
1760 { "demi", SkFontStyle::kSemiBold_Weight }, 1732 { "demi", SkFontStyle::kSemiBold_Weight },
1761 { "demibold", SkFontStyle::kSemiBold_Weight }, 1733 { "demibold", SkFontStyle::kSemiBold_Weight },
1762 { "extra", SkFontStyle::kExtraBold_Weight },
1763 { "extrabold", SkFontStyle::kExtraBold_Weight }, 1734 { "extrabold", SkFontStyle::kExtraBold_Weight },
1764 { "extralight", SkFontStyle::kExtraLight_Weight }, 1735 { "extralight", SkFontStyle::kExtraLight_Weight },
1765 { "hairline", SkFontStyle::kThin_Weight },
1766 { "heavy", SkFontStyle::kBlack_Weight }, 1736 { "heavy", SkFontStyle::kBlack_Weight },
1767 { "light", SkFontStyle::kLight_Weight }, 1737 { "light", SkFontStyle::kLight_Weight },
1768 { "medium", SkFontStyle::kMedium_Weight }, 1738 { "medium", SkFontStyle::kMedium_Weight },
1769 { "normal", SkFontStyle::kNormal_Weight }, 1739 { "normal", SkFontStyle::kNormal_Weight },
1770 { "plain", SkFontStyle::kNormal_Weight },
1771 { "regular", SkFontStyle::kNormal_Weight }, 1740 { "regular", SkFontStyle::kNormal_Weight },
1772 { "roman", SkFontStyle::kNormal_Weight },
1773 { "semibold", SkFontStyle::kSemiBold_Weight }, 1741 { "semibold", SkFontStyle::kSemiBold_Weight },
1774 { "standard", SkFontStyle::kNormal_Weight },
1775 { "thin", SkFontStyle::kThin_Weight }, 1742 { "thin", SkFontStyle::kThin_Weight },
1776 { "ultra", SkFontStyle::kExtraBold_Weight }, 1743 { "ultra", SkFontStyle::kExtraBold_Weight },
1777 { "ultrablack", 1000 }, 1744 { "ultrablack", 1000 },
1778 { "ultrabold", SkFontStyle::kExtraBold_Weight }, 1745 { "ultrabold", SkFontStyle::kExtraBold_Weight },
1779 { "ultraheavy", 1000 }, 1746 { "ultraheavy", 1000 },
1780 { "ultralight", SkFontStyle::kExtraLight_Weight }, 1747 { "ultralight", SkFontStyle::kExtraLight_Weight },
1781 }; 1748 };
1782 int const index = SkStrLCSearch(&commonWeights[0].name, SK_ARRAY_COUNT(c ommonWeights), 1749 int const index = SkStrLCSearch(&commonWeights[0].name, SK_ARRAY_COUNT(c ommonWeights),
1783 psFontInfo.weight, sizeof(commonWeights[ 0])); 1750 psFontInfo.weight, sizeof(commonWeights[ 0]));
1784 if (index >= 0) { 1751 if (index >= 0) {
1785 weight = commonWeights[index].weight; 1752 weight = commonWeights[index].weight;
1786 } else { 1753 } else {
1787 SkDEBUGF(("Do not know weight for: %s (%s) \n", face->family_name, p sFontInfo.weight)); 1754 SkDEBUGF(("Do not know weight for: %s\n", psFontInfo.weight));
1788 } 1755 }
1789 } 1756 }
1790 1757
1791 if (name) { 1758 if (name) {
1792 name->set(face->family_name); 1759 name->set(face->family_name);
1793 } 1760 }
1794 if (style) { 1761 if (style) {
1795 *style = SkFontStyle(weight, width, slant); 1762 *style = SkFontStyle(weight, width, slant);
1796 } 1763 }
1797 if (isFixedPitch) { 1764 if (isFixedPitch) {
1798 *isFixedPitch = FT_IS_FIXED_WIDTH(face); 1765 *isFixedPitch = FT_IS_FIXED_WIDTH(face);
1799 } 1766 }
1800 1767
1801 FT_Done_Face(face); 1768 FT_Done_Face(face);
1769 FT_Done_FreeType(library);
1802 return true; 1770 return true;
1803 } 1771 }
OLDNEW
« no previous file with comments | « src/fonts/SkFontMgr_fontconfig.cpp ('k') | src/ports/SkFontHost_FreeType_common.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698