initial import
[vuplus_webkit] / Source / WebCore / platform / graphics / chromium / UniscribeHelperTextRun.h
1 /*
2  * Copyright (c) 2006, 2007, 2008, 2009, Google Inc. All rights reserved.
3  * 
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  * 
8  *     * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  *     * Neither the name of Google Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  * 
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30
31 #ifndef UniscribeHelperTextRun_h
32 #define UniscribeHelperTextRun_h
33
34 #include "UniscribeHelper.h"
35
36 namespace WebCore {
37
38 class Font;
39 class TextRun;
40
41 // Wrapper around the Uniscribe helper that automatically sets it up with the
42 // WebKit types we supply.
43 class UniscribeHelperTextRun : public UniscribeHelper {
44 public:
45     // Regular constructor used for WebCore text run processing.
46     UniscribeHelperTextRun(const TextRun&, const Font&);
47
48     // Constructor with the same interface as the gfx::UniscribeState. Using
49     // this constructor will not give you font fallback, but it will provide
50     // the ability to load fonts that may not be in the OS cache
51     // ("TryToPreloadFont") if the caller does not have a TextRun/Font.
52     UniscribeHelperTextRun(const wchar_t* input,
53                            int inputLength,
54                            bool isRtl,
55                            HFONT hfont,
56                            SCRIPT_CACHE*,
57                            SCRIPT_FONTPROPERTIES*);
58
59 protected:
60     virtual void tryToPreloadFont(HFONT);
61
62 private:
63     // This function retrieves the Windows font data (HFONT, etc) for the next
64     // WebKit font in the list. If the font data corresponding to font_index_
65     // has been obtained before, returns the values stored in our internal
66     // vectors (hfonts_, etc).  Otherwise, it gets next SimpleFontData from
67     // WebKit and adds them to in hfonts_ and friends so that font data can be
68     // returned quickly next time they're requested.
69     virtual bool nextWinFontData(HFONT*, SCRIPT_CACHE**, SCRIPT_FONTPROPERTIES**, int* ascent);
70     virtual void resetFontIndex();
71
72     // Reference to WebKit::Font that contains all the information about fonts
73     // we can use to render this input run of text.  It is used in
74     // NextWinFontData to retrieve Windows font data for a series of
75     // non-primary fonts.
76     //
77     // This pointer can be NULL for no font fallback handling.
78     const Font* m_font;
79
80     // It's rare that many fonts are listed in stylesheets.
81     // Four would be large enough in most cases.
82     const static size_t kNumberOfFonts = 4;
83
84     // These vectors are used to store Windows font data for non-primary fonts.
85     Vector<HFONT, kNumberOfFonts> m_hfonts;
86     Vector<SCRIPT_CACHE*, kNumberOfFonts> m_scriptCaches;
87     Vector<SCRIPT_FONTPROPERTIES*, kNumberOfFonts> m_fontProperties;
88     Vector<int, kNumberOfFonts> m_ascents;
89
90     // Index of the fallback font we're currently using for NextWinFontData.
91     int m_fontIndex;
92 };
93
94 }  // namespace WebCore
95
96 #endif  // UniscribeHelperTextRun_h