2 * Copyright 2012 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
9 #ifndef SkTypeface_android_DEFINED
10 #define SkTypeface_android_DEFINED
12 #include "SkTypeface.h"
14 #ifdef SK_BUILD_FOR_ANDROID
16 class SkPaintOptionsAndroid;
19 * Get the family name of the font in the fallback font list containing
20 * the specified character using the system's default language. This function
21 * also assumes the only families with the elegant or default variants will be
24 * @param uni The unicode character to use for the lookup.
25 * @param name The family name of the font file containing the unicode character
26 * in the default language
27 * @return true if a font is found and false otherwise
29 SK_API bool SkGetFallbackFamilyNameForChar(SkUnichar uni, SkString* name);
32 * Get the family name of the font in the fallback font list containing
33 * the specified character taking into account the provided language. This
34 * function also assumes the only families with the elegant or default variants
37 * @param uni The unicode character to use for the lookup.
38 * @param lang The null terminated string representing the BCP 47 language
39 * identifier for the preferred language. If there is no unique
40 * fallback chain for that language the system's default language
42 * @param name The family name of the font file containing the unicode character
43 * in the preferred language
44 * @return true if a font is found and false otherwise
46 SK_API bool SkGetFallbackFamilyNameForChar(SkUnichar uni, const char* lang, SkString* name);
50 * Load font config from given xml files, instead of those from Android system.
52 SK_API void SkUseTestFontConfigFile(const char* mainconf, const char* fallbackconf,
53 const char* fontsdir);
56 * Given a "current" fontID, return a ref to the next logical typeface
57 * when searching fonts for a given unicode value. Typically the caller
58 * will query a given font, and if a unicode value is not supported, they
59 * will call this, and if 0 is not returned, will search that font, and so
60 * on. This process must be finite, and when the fonthost sees a
61 * font with no logical successor, it must return NULL.
63 * The original fontID is also provided. This is the initial font that was
64 * stored in the typeface of the caller. It is provided as an aid to choose
65 * the best next logical font. e.g. If the original font was bold or serif,
66 * but the 2nd in the logical chain was plain, then a subsequent call to
67 * get the 3rd can still inspect the original, and try to match its
68 * stylistic attributes.
70 SkTypeface* SkAndroidNextLogicalTypeface(SkFontID currFontID, SkFontID origFontID,
71 const SkPaintOptionsAndroid& options);
74 * Given a glyphID (built using fallback font chaining) and its origin typeface
75 * return the actual typeface within the fallback chain that this glyphID
76 * resolves to. If no suitable typeface is found then NULL is returned. However,
77 * if returned typeface is not NULL it is assumed to be globally cached so the
78 * caller need not ref it.
80 * Optionally, if lower/upper bound params are provided and the returned
81 * typeface is not NULL, then these params are populated with the range of
82 * glyphIDs that this typeface is capable of resolving. The lower bound is
83 * inclusive while the upper bound is exclusive.
85 SkTypeface* SkGetTypefaceForGlyphID(uint16_t glyphID, const SkTypeface* origTypeface,
86 const SkPaintOptionsAndroid& options,
87 int* lowerBounds = NULL, int* upperBounds = NULL);
89 #endif // #ifdef SK_BUILD_FOR_ANDROID
90 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
92 #include "SkPaintOptionsAndroid.h"
93 #include "../harfbuzz/src/harfbuzz-shaper.h"
94 #include "../harfbuzz_ng/src/hb.h"
97 * Return a new typeface for a fallback script. If the script is
98 * not valid, or can not map to a font, returns null.
99 * @param script The harfbuzz script id.
100 * @param style The font style, for example bold
101 * @param elegant true if we want the web friendly elegant version of the font
102 * @return reference to the matching typeface. Caller must call
103 * unref() when they are done.
105 SK_API SkTypeface* SkCreateTypefaceForScriptNG(hb_script_t script, SkTypeface::Style style,
106 SkPaintOptionsAndroid::FontVariant fontVariant = SkPaintOptionsAndroid::kDefault_Variant);
108 SK_API SkTypeface* SkCreateTypefaceForScript(HB_Script script, SkTypeface::Style style,
109 SkPaintOptionsAndroid::FontVariant fontVariant = SkPaintOptionsAndroid::kDefault_Variant);
111 #endif // #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
112 #endif // #ifndef SkTypeface_android_DEFINED