blob: f00db468f2d0d4da7b4aa2d895d80f3f54cfaac7 [file] [log] [blame]
license.botf003cfe2008-08-24 09:55:55 +09001// 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.commit3f4a7322008-07-27 06:49:38 +09004//
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
16namespace 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.
22enum 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.comdbff4f52008-08-19 01:00:38 +090033// It can return NULL and a caller has to implement its own fallback.
initial.commit3f4a7322008-07-27 06:49:38 +090034const wchar_t* GetFontFamilyForScript(UScriptCode script,
35 GenericFamilyType generic);
36
37// Return a font family that can render |characters| based on
jungshik@google.com3ce34ed2008-08-08 10:36:12 +090038// 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.
43const wchar_t* GetFallbackFamily(const wchar_t* characters,
44 int length,
45 GenericFamilyType generic,
46 UChar32 *char_checked,
47 UScriptCode *script_checked);
initial.commit3f4a7322008-07-27 06:49:38 +090048// 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.
66bool GetDerivedFontData(const wchar_t *family,
67 int style,
68 LOGFONT *logfont,
69 int *ascent,
70 HFONT *hfont,
71 SCRIPT_CACHE **script_cache);
72
73enum {
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.
82int GetStyleFromLogfont(const LOGFONT *logfont);
83
84} // namespace gfx
85
86#endif // BASE_GFX_FONT_UTILS_H__
license.botf003cfe2008-08-24 09:55:55 +090087