OLD | NEW |
---|---|
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 Loading... | |
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 /* Exported so that SkFontMgrs can make use of our ability to extract |
1674 ability to extract the name+style from a stream, using FreeType's api. | 1674 * name and style from a stream, using FreeType's API. |
1675 */ | 1675 */ |
1676 bool find_name_and_attributes(SkStream* stream, SkString* name, | 1676 bool find_name_and_attributes(SkStream* stream, int ttcIndex, |
tomhudson
2014/07/11 13:30:21
If we're exporting this, shouldn't it have an SkCa
bungeman-skia
2014/07/11 14:33:26
Sure, why not. It wasn't static to begin with, so
| |
1677 SkTypeface::Style* style, bool* isFixedPitch) { | 1677 SkString* name, SkTypeface::Style* style, bool* is FixedPitch) |
1678 { | |
1678 FT_Library library; | 1679 FT_Library library; |
1679 if (FT_Init_FreeType(&library)) { | 1680 if (FT_Init_FreeType(&library)) { |
1680 return false; | 1681 return false; |
1681 } | 1682 } |
1682 | 1683 |
1683 FT_Open_Args args; | 1684 FT_Open_Args args; |
1684 memset(&args, 0, sizeof(args)); | 1685 memset(&args, 0, sizeof(args)); |
1685 | 1686 |
1686 const void* memoryBase = stream->getMemoryBase(); | 1687 const void* memoryBase = stream->getMemoryBase(); |
1687 FT_StreamRec streamRec; | 1688 FT_StreamRec streamRec; |
1688 | 1689 |
1689 if (NULL != memoryBase) { | 1690 if (NULL != memoryBase) { |
1690 args.flags = FT_OPEN_MEMORY; | 1691 args.flags = FT_OPEN_MEMORY; |
1691 args.memory_base = (const FT_Byte*)memoryBase; | 1692 args.memory_base = (const FT_Byte*)memoryBase; |
1692 args.memory_size = stream->getLength(); | 1693 args.memory_size = stream->getLength(); |
1693 } else { | 1694 } else { |
1694 memset(&streamRec, 0, sizeof(streamRec)); | 1695 memset(&streamRec, 0, sizeof(streamRec)); |
1695 streamRec.size = stream->getLength(); | 1696 streamRec.size = stream->getLength(); |
1696 streamRec.descriptor.pointer = stream; | 1697 streamRec.descriptor.pointer = stream; |
1697 streamRec.read = sk_stream_read; | 1698 streamRec.read = sk_stream_read; |
1698 streamRec.close = sk_stream_close; | 1699 streamRec.close = sk_stream_close; |
1699 | 1700 |
1700 args.flags = FT_OPEN_STREAM; | 1701 args.flags = FT_OPEN_STREAM; |
1701 args.stream = &streamRec; | 1702 args.stream = &streamRec; |
1702 } | 1703 } |
1703 | 1704 |
1704 FT_Face face; | 1705 FT_Face face; |
1705 if (FT_Open_Face(library, &args, 0, &face)) { | 1706 if (FT_Open_Face(library, &args, ttcIndex, &face)) { |
1706 FT_Done_FreeType(library); | 1707 FT_Done_FreeType(library); |
1707 return false; | 1708 return false; |
1708 } | 1709 } |
1709 | 1710 |
1710 int tempStyle = SkTypeface::kNormal; | 1711 int tempStyle = SkTypeface::kNormal; |
1711 if (face->style_flags & FT_STYLE_FLAG_BOLD) { | 1712 if (face->style_flags & FT_STYLE_FLAG_BOLD) { |
1712 tempStyle |= SkTypeface::kBold; | 1713 tempStyle |= SkTypeface::kBold; |
1713 } | 1714 } |
1714 if (face->style_flags & FT_STYLE_FLAG_ITALIC) { | 1715 if (face->style_flags & FT_STYLE_FLAG_ITALIC) { |
1715 tempStyle |= SkTypeface::kItalic; | 1716 tempStyle |= SkTypeface::kItalic; |
1716 } | 1717 } |
1717 | 1718 |
1718 if (name) { | 1719 if (name) { |
1719 name->set(face->family_name); | 1720 name->set(face->family_name); |
1720 } | 1721 } |
1721 if (style) { | 1722 if (style) { |
1722 *style = (SkTypeface::Style) tempStyle; | 1723 *style = (SkTypeface::Style) tempStyle; |
1723 } | 1724 } |
1724 if (isFixedPitch) { | 1725 if (isFixedPitch) { |
1725 *isFixedPitch = FT_IS_FIXED_WIDTH(face); | 1726 *isFixedPitch = FT_IS_FIXED_WIDTH(face); |
1726 } | 1727 } |
1727 | 1728 |
1728 FT_Done_Face(face); | 1729 FT_Done_Face(face); |
1729 FT_Done_FreeType(library); | 1730 FT_Done_FreeType(library); |
1730 return true; | 1731 return true; |
1731 } | 1732 } |
OLD | NEW |