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

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

Issue 488143002: Replace SkTypeface::Style with SkFontStyle. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add expectations, remove whitespace. Created 6 years, 2 months 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/ports/SkFontConfigTypeface.h ('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 #include "SkTSearch.h"
1672 /*static*/ bool SkTypeface_FreeType::ScanFont( 1673 /*static*/ bool SkTypeface_FreeType::ScanFont(
1673 SkStream* stream, int ttcIndex, SkString* name, SkTypeface::Style* style, bo ol* isFixedPitch) 1674 SkStream* stream, int ttcIndex, SkString* name, SkFontStyle* style, bool* is FixedPitch)
1674 { 1675 {
1675 FT_Library library; 1676 FT_Library library;
1676 if (FT_Init_FreeType(&library)) { 1677 if (FT_Init_FreeType(&library)) {
1677 return false; 1678 return false;
1678 } 1679 }
1679 1680
1680 FT_Open_Args args; 1681 FT_Open_Args args;
1681 memset(&args, 0, sizeof(args)); 1682 memset(&args, 0, sizeof(args));
1682 1683
1683 const void* memoryBase = stream->getMemoryBase(); 1684 const void* memoryBase = stream->getMemoryBase();
(...skipping 13 matching lines...) Expand all
1697 args.flags = FT_OPEN_STREAM; 1698 args.flags = FT_OPEN_STREAM;
1698 args.stream = &streamRec; 1699 args.stream = &streamRec;
1699 } 1700 }
1700 1701
1701 FT_Face face; 1702 FT_Face face;
1702 if (FT_Open_Face(library, &args, ttcIndex, &face)) { 1703 if (FT_Open_Face(library, &args, ttcIndex, &face)) {
1703 FT_Done_FreeType(library); 1704 FT_Done_FreeType(library);
1704 return false; 1705 return false;
1705 } 1706 }
1706 1707
1707 int tempStyle = SkTypeface::kNormal; 1708 int weight = SkFontStyle::kNormal_Weight;
1709 int width = SkFontStyle::kNormal_Width;
1710 SkFontStyle::Slant slant = SkFontStyle::kUpright_Slant;
1708 if (face->style_flags & FT_STYLE_FLAG_BOLD) { 1711 if (face->style_flags & FT_STYLE_FLAG_BOLD) {
1709 tempStyle |= SkTypeface::kBold; 1712 weight = SkFontStyle::kBold_Weight;
1710 } 1713 }
1711 if (face->style_flags & FT_STYLE_FLAG_ITALIC) { 1714 if (face->style_flags & FT_STYLE_FLAG_ITALIC) {
1712 tempStyle |= SkTypeface::kItalic; 1715 slant = SkFontStyle::kItalic_Slant;
1716 }
1717
1718 PS_FontInfoRec psFontInfo;
1719 TT_OS2* os2 = static_cast<TT_OS2*>(FT_Get_Sfnt_Table(face, ft_sfnt_os2));
1720 if (os2 && os2->version != 0xffff) {
1721 weight = os2->usWeightClass;
1722 width = os2->usWidthClass;
1723 } else if (0 == FT_Get_PS_Font_Info(face, &psFontInfo) && psFontInfo.weight) {
1724 static const struct {
1725 char const * const name;
1726 int const weight;
1727 } commonWeights [] = {
1728 // There are probably more common names, but these are known to exis t.
1729 { "black", SkFontStyle::kBlack_Weight },
1730 { "bold", SkFontStyle::kBold_Weight },
1731 { "book", (SkFontStyle::kNormal_Weight + SkFontStyle::kLight_Weight) /2 },
1732 { "demi", SkFontStyle::kSemiBold_Weight },
1733 { "demibold", SkFontStyle::kSemiBold_Weight },
1734 { "extrabold", SkFontStyle::kExtraBold_Weight },
1735 { "extralight", SkFontStyle::kExtraLight_Weight },
1736 { "heavy", SkFontStyle::kBlack_Weight },
1737 { "light", SkFontStyle::kLight_Weight },
1738 { "medium", SkFontStyle::kMedium_Weight },
1739 { "normal", SkFontStyle::kNormal_Weight },
1740 { "regular", SkFontStyle::kNormal_Weight },
1741 { "semibold", SkFontStyle::kSemiBold_Weight },
1742 { "thin", SkFontStyle::kThin_Weight },
1743 { "ultra", SkFontStyle::kExtraBold_Weight },
1744 { "ultrablack", 1000 },
1745 { "ultrabold", SkFontStyle::kExtraBold_Weight },
1746 { "ultraheavy", 1000 },
1747 { "ultralight", SkFontStyle::kExtraLight_Weight },
1748 };
1749 int const index = SkStrLCSearch(&commonWeights[0].name, SK_ARRAY_COUNT(c ommonWeights),
1750 psFontInfo.weight, sizeof(commonWeights) );
1751 if (index >= 0) {
1752 weight = commonWeights[index].weight;
1753 } else {
1754 SkDEBUGF(("Do not know weight for: %s\n", psFontInfo.weight));
1755 }
1713 } 1756 }
1714 1757
1715 if (name) { 1758 if (name) {
1716 name->set(face->family_name); 1759 name->set(face->family_name);
1717 } 1760 }
1718 if (style) { 1761 if (style) {
1719 *style = (SkTypeface::Style) tempStyle; 1762 *style = SkFontStyle(weight, width, slant);
1720 } 1763 }
1721 if (isFixedPitch) { 1764 if (isFixedPitch) {
1722 *isFixedPitch = FT_IS_FIXED_WIDTH(face); 1765 *isFixedPitch = FT_IS_FIXED_WIDTH(face);
1723 } 1766 }
1724 1767
1725 FT_Done_Face(face); 1768 FT_Done_Face(face);
1726 FT_Done_FreeType(library); 1769 FT_Done_FreeType(library);
1727 return true; 1770 return true;
1728 } 1771 }
OLDNEW
« no previous file with comments | « src/ports/SkFontConfigTypeface.h ('k') | src/ports/SkFontHost_FreeType_common.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698