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

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

Issue 667023002: Revert of Replace SkTypeface::Style with SkFontStyle. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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"
1673 /*static*/ bool SkTypeface_FreeType::ScanFont( 1672 /*static*/ bool SkTypeface_FreeType::ScanFont(
1674 SkStream* stream, int ttcIndex, SkString* name, SkFontStyle* style, bool* is FixedPitch) 1673 SkStream* stream, int ttcIndex, SkString* name, SkTypeface::Style* style, bo ol* isFixedPitch)
1675 { 1674 {
1676 FT_Library library; 1675 FT_Library library;
1677 if (FT_Init_FreeType(&library)) { 1676 if (FT_Init_FreeType(&library)) {
1678 return false; 1677 return false;
1679 } 1678 }
1680 1679
1681 FT_Open_Args args; 1680 FT_Open_Args args;
1682 memset(&args, 0, sizeof(args)); 1681 memset(&args, 0, sizeof(args));
1683 1682
1684 const void* memoryBase = stream->getMemoryBase(); 1683 const void* memoryBase = stream->getMemoryBase();
(...skipping 13 matching lines...) Expand all
1698 args.flags = FT_OPEN_STREAM; 1697 args.flags = FT_OPEN_STREAM;
1699 args.stream = &streamRec; 1698 args.stream = &streamRec;
1700 } 1699 }
1701 1700
1702 FT_Face face; 1701 FT_Face face;
1703 if (FT_Open_Face(library, &args, ttcIndex, &face)) { 1702 if (FT_Open_Face(library, &args, ttcIndex, &face)) {
1704 FT_Done_FreeType(library); 1703 FT_Done_FreeType(library);
1705 return false; 1704 return false;
1706 } 1705 }
1707 1706
1708 int weight = SkFontStyle::kNormal_Weight; 1707 int tempStyle = SkTypeface::kNormal;
1709 int width = SkFontStyle::kNormal_Width;
1710 SkFontStyle::Slant slant = SkFontStyle::kUpright_Slant;
1711 if (face->style_flags & FT_STYLE_FLAG_BOLD) { 1708 if (face->style_flags & FT_STYLE_FLAG_BOLD) {
1712 weight = SkFontStyle::kBold_Weight; 1709 tempStyle |= SkTypeface::kBold;
1713 } 1710 }
1714 if (face->style_flags & FT_STYLE_FLAG_ITALIC) { 1711 if (face->style_flags & FT_STYLE_FLAG_ITALIC) {
1715 slant = SkFontStyle::kItalic_Slant; 1712 tempStyle |= SkTypeface::kItalic;
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 }
1756 } 1713 }
1757 1714
1758 if (name) { 1715 if (name) {
1759 name->set(face->family_name); 1716 name->set(face->family_name);
1760 } 1717 }
1761 if (style) { 1718 if (style) {
1762 *style = SkFontStyle(weight, width, slant); 1719 *style = (SkTypeface::Style) tempStyle;
1763 } 1720 }
1764 if (isFixedPitch) { 1721 if (isFixedPitch) {
1765 *isFixedPitch = FT_IS_FIXED_WIDTH(face); 1722 *isFixedPitch = FT_IS_FIXED_WIDTH(face);
1766 } 1723 }
1767 1724
1768 FT_Done_Face(face); 1725 FT_Done_Face(face);
1769 FT_Done_FreeType(library); 1726 FT_Done_FreeType(library);
1770 return true; 1727 return true;
1771 } 1728 }
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