📄 uniscribehelper.h
字号:
/* * Copyright (c) 2006, 2007, 2008, 2009, Google Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following disclaimer * in the documentation and/or other materials provided with the * distribution. * * Neither the name of Google Inc. nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */// A wrapper around Uniscribe that provides a reasonable API.#ifndef UniscribeHelper_h#define UniscribeHelper_h#include <windows.h>#include <usp10.h>#include <map>#include <unicode/uchar.h>#include <wtf/Vector.h>class UniscribeTest_TooBig_Test; // A gunit test for UniscribeHelper.namespace WebCore {class GraphicsContext;#define UNISCRIBE_HELPER_STACK_RUNS 8#define UNISCRIBE_HELPER_STACK_CHARS 32// This object should be safe to create & destroy frequently, as long as the// caller preserves the script_cache when possible (this data may be slow to// compute).//// This object is "kind of large" (~1K) because it reserves a lot of space for// working with to avoid expensive heap operations. Therefore, not only should// you not worry about creating and destroying it, you should try to not keep// them around.class UniscribeHelper {public: // Initializes this Uniscribe run with the text pointed to by |run| with // |length|. The input is NOT null terminated. // // The is_rtl flag should be set if the input script is RTL. It is assumed // that the caller has already divided up the input text (using ICU, for // example) into runs of the same direction of script. This avoids // disagreements between the caller and Uniscribe later (see FillItems). // // A script cache should be provided by the caller that is initialized to // NULL. When the caller is done with the cache (it may be stored between // runs as long as it is used consistently with the same HFONT), it should // call ScriptFreeCache(). UniscribeHelper(const UChar* input, int inputLength, bool isRtl, HFONT, SCRIPT_CACHE*, SCRIPT_FONTPROPERTIES*); virtual ~UniscribeHelper(); // Sets Uniscribe's directional override flag. False by default. bool directionalOverride() const { return m_directionalOverride; } void setDirectionalOverride(bool override) { m_directionalOverride = override; } // Set's Uniscribe's no-ligate override flag. False by default. bool inhibitLigate() const { return m_inhibitLigate; } void setInhibitLigate(bool inhibit) { m_inhibitLigate = inhibit; } // Set letter spacing. We will try to insert this much space between // graphemes (one or more glyphs perceived as a single unit by ordinary // users of a script). Positive values increase letter spacing, negative // values decrease it. 0 by default. int letterSpacing() const { return m_letterSpacing; } void setLetterSpacing(int letterSpacing) { m_letterSpacing = letterSpacing; } // Set the width of a standard space character. We use this to normalize // space widths. Windows will make spaces after Hindi characters larger than // other spaces. A space_width of 0 means to use the default space width. // // Must be set before Init() is called. int spaceWidth() const { return m_spaceWidth; } void setSpaceWidth(int spaceWidth) { m_spaceWidth = spaceWidth; } // Set word spacing. We will try to insert this much extra space between // each word in the input (beyond whatever whitespace character separates // words). Positive values lead to increased letter spacing, negative values // decrease it. 0 by default. // // Must be set before Init() is called. int wordSpacing() const { return m_wordSpacing; } void setWordSpacing(int wordSpacing) { m_wordSpacing = wordSpacing; } void setAscent(int ascent) { m_ascent = ascent; } // When set to true, this class is used only to look up glyph // indices for a range of Unicode characters without glyph placement. // By default, it's false. This should be set to true when this // class is used for glyph index look-up for non-BMP characters // in GlyphPageNodeChromiumWin.cpp. void setDisableFontFallback(bool disableFontFallback) { m_disableFontFallback = true; } // You must call this after setting any options but before doing any // other calls like asking for widths or drawing. void init() { initWithOptionalLengthProtection(true); } // Returns the total width in pixels of the text run. int width() const; // Call to justify the text, with the amount of space that should be ADDED // to get the desired width that the column should be justified to. // Normally, spaces are inserted, but for Arabic there will be kashidas // (extra strokes) inserted instead. // // This function MUST be called AFTER Init(). void justify(int additionalSpace); // Computes the given character offset into a pixel offset of the beginning // of that character. int characterToX(int offset) const; // Converts the given pixel X position into a logical character offset into // the run. For positions appearing before the first character, this will // return -1. int xToCharacter(int x) const; // Draws the given characters to (x, y) in the given DC. The font will be // handled by this function, but the font color and other attributes should // be pre-set. // // The y position is the upper left corner, NOT the baseline. void draw(GraphicsContext* graphicsContext, HDC dc, int x, int y, int from, int to); // Returns the first glyph assigned to the character at the given offset. // This function is used to retrieve glyph information when Uniscribe is // being used to generate glyphs for non-complex, non-BMP (above U+FFFF) // characters. These characters are not otherwise special and have no // complex shaping rules, so we don't otherwise need Uniscribe, except // Uniscribe is the only way to get glyphs for non-BMP characters. // // Returns 0 if there is no glyph for the given character. WORD firstGlyphForCharacter(int charOffset) const;protected: // Backend for init. The flag allows the unit test to specify whether we // should fail early for very long strings like normal, or try to pass the // long string to Uniscribe. The latter provides a way to force failure of
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -