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

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

Issue 382053003: Update find_name_and_attributes to take ttc index. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Move find_name_and_attributes to SkTypeface_FreeType::ScanFont. Created 6 years, 5 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/SkFontConfigInterface_android.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 1652 matching lines...) Expand 10 before | Expand all | Expand 10 after
1663 return 0; 1663 return 0;
1664 } 1664 }
1665 } 1665 }
1666 1666
1667 return size; 1667 return size;
1668 } 1668 }
1669 1669
1670 /////////////////////////////////////////////////////////////////////////////// 1670 ///////////////////////////////////////////////////////////////////////////////
1671 /////////////////////////////////////////////////////////////////////////////// 1671 ///////////////////////////////////////////////////////////////////////////////
1672 1672
1673 /* Export this so that other parts of our FonttHost port can make use of our 1673 /*static*/ bool SkTypeface_FreeType::ScanFont(
1674 ability to extract the name+style from a stream, using FreeType's api. 1674 SkStream* stream, int ttcIndex, SkString* name, SkTypeface::Style* style, bo ol* isFixedPitch)
1675 */ 1675 {
1676 bool find_name_and_attributes(SkStream* stream, SkString* name,
1677 SkTypeface::Style* style, bool* isFixedPitch) {
1678 FT_Library library; 1676 FT_Library library;
1679 if (FT_Init_FreeType(&library)) { 1677 if (FT_Init_FreeType(&library)) {
1680 return false; 1678 return false;
1681 } 1679 }
1682 1680
1683 FT_Open_Args args; 1681 FT_Open_Args args;
1684 memset(&args, 0, sizeof(args)); 1682 memset(&args, 0, sizeof(args));
1685 1683
1686 const void* memoryBase = stream->getMemoryBase(); 1684 const void* memoryBase = stream->getMemoryBase();
1687 FT_StreamRec streamRec; 1685 FT_StreamRec streamRec;
1688 1686
1689 if (NULL != memoryBase) { 1687 if (NULL != memoryBase) {
1690 args.flags = FT_OPEN_MEMORY; 1688 args.flags = FT_OPEN_MEMORY;
1691 args.memory_base = (const FT_Byte*)memoryBase; 1689 args.memory_base = (const FT_Byte*)memoryBase;
1692 args.memory_size = stream->getLength(); 1690 args.memory_size = stream->getLength();
1693 } else { 1691 } else {
1694 memset(&streamRec, 0, sizeof(streamRec)); 1692 memset(&streamRec, 0, sizeof(streamRec));
1695 streamRec.size = stream->getLength(); 1693 streamRec.size = stream->getLength();
1696 streamRec.descriptor.pointer = stream; 1694 streamRec.descriptor.pointer = stream;
1697 streamRec.read = sk_stream_read; 1695 streamRec.read = sk_stream_read;
1698 streamRec.close = sk_stream_close; 1696 streamRec.close = sk_stream_close;
1699 1697
1700 args.flags = FT_OPEN_STREAM; 1698 args.flags = FT_OPEN_STREAM;
1701 args.stream = &streamRec; 1699 args.stream = &streamRec;
1702 } 1700 }
1703 1701
1704 FT_Face face; 1702 FT_Face face;
1705 if (FT_Open_Face(library, &args, 0, &face)) { 1703 if (FT_Open_Face(library, &args, ttcIndex, &face)) {
1706 FT_Done_FreeType(library); 1704 FT_Done_FreeType(library);
1707 return false; 1705 return false;
1708 } 1706 }
1709 1707
1710 int tempStyle = SkTypeface::kNormal; 1708 int tempStyle = SkTypeface::kNormal;
1711 if (face->style_flags & FT_STYLE_FLAG_BOLD) { 1709 if (face->style_flags & FT_STYLE_FLAG_BOLD) {
1712 tempStyle |= SkTypeface::kBold; 1710 tempStyle |= SkTypeface::kBold;
1713 } 1711 }
1714 if (face->style_flags & FT_STYLE_FLAG_ITALIC) { 1712 if (face->style_flags & FT_STYLE_FLAG_ITALIC) {
1715 tempStyle |= SkTypeface::kItalic; 1713 tempStyle |= SkTypeface::kItalic;
1716 } 1714 }
1717 1715
1718 if (name) { 1716 if (name) {
1719 name->set(face->family_name); 1717 name->set(face->family_name);
1720 } 1718 }
1721 if (style) { 1719 if (style) {
1722 *style = (SkTypeface::Style) tempStyle; 1720 *style = (SkTypeface::Style) tempStyle;
1723 } 1721 }
1724 if (isFixedPitch) { 1722 if (isFixedPitch) {
1725 *isFixedPitch = FT_IS_FIXED_WIDTH(face); 1723 *isFixedPitch = FT_IS_FIXED_WIDTH(face);
1726 } 1724 }
1727 1725
1728 FT_Done_Face(face); 1726 FT_Done_Face(face);
1729 FT_Done_FreeType(library); 1727 FT_Done_FreeType(library);
1730 return true; 1728 return true;
1731 } 1729 }
OLDNEW
« no previous file with comments | « src/ports/SkFontConfigInterface_android.cpp ('k') | src/ports/SkFontHost_FreeType_common.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698