license.bot | f003cfe | 2008-08-24 09:55:55 +0900 | [diff] [blame^] | 1 | // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 4 | // |
| 5 | // A collection of utilities for font handling. |
| 6 | |
| 7 | #ifndef BASE_GFX_FONT_UTILS_H__ |
| 8 | #define BASE_GFX_FONT_UTILS_H__ |
| 9 | |
| 10 | #include <usp10.h> |
| 11 | #include <wchar.h> |
| 12 | #include <windows.h> |
| 13 | |
| 14 | #include <unicode/uscript.h> |
| 15 | |
| 16 | namespace gfx { |
| 17 | |
| 18 | // The order of family types needs to be exactly the same as |
| 19 | // WebCore::FontDescription::GenericFamilyType. We may lift that restriction |
| 20 | // when we make webkit_glue::WebkitGenericToChromeGenericFamily more |
| 21 | // intelligent. |
| 22 | enum GenericFamilyType { |
| 23 | GENERIC_FAMILY_NONE = 0, |
| 24 | GENERIC_FAMILY_STANDARD, |
| 25 | GENERIC_FAMILY_SERIF, |
| 26 | GENERIC_FAMILY_SANSSERIF, |
| 27 | GENERIC_FAMILY_MONOSPACE, |
| 28 | GENERIC_FAMILY_CURSIVE, |
| 29 | GENERIC_FAMILY_FANTASY |
| 30 | }; |
| 31 | |
| 32 | // Return a font family that supports a script and belongs to |generic| font family. |
ericroman@google.com | dbff4f5 | 2008-08-19 01:00:38 +0900 | [diff] [blame] | 33 | // It can return NULL and a caller has to implement its own fallback. |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 34 | const wchar_t* GetFontFamilyForScript(UScriptCode script, |
| 35 | GenericFamilyType generic); |
| 36 | |
| 37 | // Return a font family that can render |characters| based on |
jungshik@google.com | 3ce34ed | 2008-08-08 10:36:12 +0900 | [diff] [blame] | 38 | // what script characters belong to. When char_checked is non-NULL, |
| 39 | // it's filled with the character used to determine the script. |
| 40 | // When script_checked is non-NULL, the script used to determine |
| 41 | // the family is returned. |
| 42 | // TODO(jungshik) : This function needs a total overhaul. |
| 43 | const wchar_t* GetFallbackFamily(const wchar_t* characters, |
| 44 | int length, |
| 45 | GenericFamilyType generic, |
| 46 | UChar32 *char_checked, |
| 47 | UScriptCode *script_checked); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 48 | // Derive a new HFONT by replacing lfFaceName of LOGFONT with |family|, |
| 49 | // calculate the ascent for the derived HFONT, and initialize SCRIPT_CACHE |
| 50 | // in FontData. |
| 51 | // |style| is only used for cache key generation. |style| is |
| 52 | // bit-wise OR of BOLD(1), UNDERLINED(2) and ITALIC(4) and |
| 53 | // should match what's contained in LOGFONT. It should be calculated |
| 54 | // by calling GetStyleFromLogFont. |
| 55 | // Returns false if the font is not accessible, in which case |ascent| field |
| 56 | // of |fontdata| is set to kUndefinedAscent. |
| 57 | // Be aware that this is not thread-safe. |
| 58 | // TODO(jungshik): Instead of having three out params, we'd better have one |
| 59 | // (|*FontData|), but somehow it mysteriously messes up the layout for |
| 60 | // certain complex script pages (e.g. hi.wikipedia.org) and also crashes |
| 61 | // at the start-up if recently visited page list includes pages with complex |
| 62 | // scripts in their title. Moreover, somehow the very first-pass of |
| 63 | // intl2 page-cycler test is noticeably slower with one out param than |
| 64 | // the current version although the subsequent 9 passes take about the |
| 65 | // same time. |
| 66 | bool GetDerivedFontData(const wchar_t *family, |
| 67 | int style, |
| 68 | LOGFONT *logfont, |
| 69 | int *ascent, |
| 70 | HFONT *hfont, |
| 71 | SCRIPT_CACHE **script_cache); |
| 72 | |
| 73 | enum { |
| 74 | FONT_STYLE_NORMAL = 0, |
| 75 | FONT_STYLE_BOLD = 1, |
| 76 | FONT_STYLE_ITALIC = 2, |
| 77 | FONT_STYLE_UNDERLINED = 4 |
| 78 | }; |
| 79 | |
| 80 | // Derive style (bit-wise OR of FONT_STYLE_BOLD, FONT_STYLE_UNDERLINED, and |
| 81 | // FONT_STYLE_ITALIC) from LOGFONT. Returns 0 if |*logfont| is NULL. |
| 82 | int GetStyleFromLogfont(const LOGFONT *logfont); |
| 83 | |
| 84 | } // namespace gfx |
| 85 | |
| 86 | #endif // BASE_GFX_FONT_UTILS_H__ |
license.bot | f003cfe | 2008-08-24 09:55:55 +0900 | [diff] [blame^] | 87 | |