Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/native/common/LEFontInstance.h
38825 views
/*1* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.2*3* This code is free software; you can redistribute it and/or modify it4* under the terms of the GNU General Public License version 2 only, as5* published by the Free Software Foundation. Oracle designates this6* particular file as subject to the "Classpath" exception as provided7* by Oracle in the LICENSE file that accompanied this code.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 2 along with this work; if not, write to the Free Software Foundation,17* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.18*19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*23*/242526/*27*28* (C) Copyright IBM Corp. 1998-2007 - All Rights Reserved29*30*/3132#ifndef __LEFONTINSTANCE_H33#define __LEFONTINSTANCE_H3435#include "LETypes.h"36/**37* \file38* \brief C++ API: Layout Engine Font Instance object39*/4041U_NAMESPACE_BEGIN4243/**44* Instances of this class are used by <code>LEFontInstance::mapCharsToGlyphs</code> and45* <code>LEFontInstance::mapCharToGlyph</code> to adjust character codes before the character46* to glyph mapping process. Examples of this are filtering out control characters47* and character mirroring - replacing a character which has both a left and a right48* hand form with the opposite form.49*50* @stable ICU 3.251*/52class LECharMapper /* not : public UObject because this is an interface/mixin class */53{54public:55/**56* Destructor.57* @stable ICU 3.258*/59virtual ~LECharMapper();6061/**62* This method does the adjustments.63*64* @param ch - the input character65*66* @return the adjusted character67*68* @stable ICU 2.869*/70virtual LEUnicode32 mapChar(LEUnicode32 ch) const = 0;71};7273/**74* This is a forward reference to the class which holds the per-glyph75* storage.76*77* @stable ICU 3.078*/79class LEGlyphStorage;8081/**82* This is a virtual base class that serves as the interface between a LayoutEngine83* and the platform font environment. It allows a LayoutEngine to access font tables, do84* character to glyph mapping, and obtain metrics information without knowing any platform85* specific details. There are also a few utility methods for converting between points,86* pixels and funits. (font design units)87*88* An instance of an <code>LEFontInstance</code> represents a font at a particular point89* size. Each instance can represent either a single physical font, or a composite font.90* A composite font is a collection of physical fonts, each of which contains a subset of91* the characters contained in the composite font.92*93* Note: with the exception of <code>getSubFont</code>, the methods in this class only94* make sense for a physical font. If you have an <code>LEFontInstance</code> which95* represents a composite font you should only call the methods below which have96* an <code>LEGlyphID</code>, an <code>LEUnicode</code> or an <code>LEUnicode32</code>97* as one of the arguments because these can be used to select a particular subfont.98*99* Subclasses which implement composite fonts should supply an implementation of these100* methods with some default behavior such as returning constant values, or using the101* values from the first subfont.102*103* @stable ICU 3.0104*/105class U_LAYOUT_API LEFontInstance : public UObject106{107public:108109/**110* This virtual destructor is here so that the subclass111* destructors can be invoked through the base class.112*113* @stable ICU 2.8114*/115virtual ~LEFontInstance();116117/**118* Get a physical font which can render the given text. For composite fonts,119* if there is no single physical font which can render all of the text,120* return a physical font which can render an initial substring of the text,121* and set the <code>offset</code> parameter to the end of that substring.122*123* Internally, the LayoutEngine works with runs of text all in the same124* font and script, so it is best to call this method with text which is125* in a single script, passing the script code in as a hint. If you don't126* know the script of the text, you can use zero, which is the script code127* for characters used in more than one script.128*129* The default implementation of this method is intended for instances of130* <code>LEFontInstance</code> which represent a physical font. It returns131* <code>this</code> and indicates that the entire string can be rendered.132*133* This method will return a valid <code>LEFontInstance</code> unless you134* have passed illegal parameters, or an internal error has been encountered.135* For composite fonts, it may return the warning <code>LE_NO_SUBFONT_WARNING</code>136* to indicate that the returned font may not be able to render all of137* the text. Whenever a valid font is returned, the <code>offset</code> parameter138* will be advanced by at least one.139*140* Subclasses which implement composite fonts must override this method.141* Where it makes sense, they should use the script code as a hint to render142* characters from the COMMON script in the font which is used for the given143* script. For example, if the input text is a series of Arabic words separated144* by spaces, and the script code passed in is <code>arabScriptCode</code> you145* should return the font used for Arabic characters for all of the input text,146* including the spaces. If, on the other hand, the input text contains characters147* which cannot be rendered by the font used for Arabic characters, but which can148* be rendered by another font, you should return that font for those characters.149*150* @param chars - the array of Unicode characters.151* @param offset - a pointer to the starting offset in the text. On exit this152* will be set the the limit offset of the text which can be153* rendered using the returned font.154* @param limit - the limit offset for the input text.155* @param script - the script hint.156* @param success - set to an error code if the arguments are illegal, or no font157* can be returned for some reason. May also be set to158* <code>LE_NO_SUBFONT_WARNING</code> if the subfont which159* was returned cannot render all of the text.160*161* @return an <code>LEFontInstance</code> for the sub font which can render the characters, or162* <code>NULL</code> if there is an error.163*164* @see LEScripts.h165*166* @stable ICU 3.2167*/168virtual const LEFontInstance *getSubFont(const LEUnicode chars[], le_int32 *offset, le_int32 limit, le_int32 script, LEErrorCode &success) const;169170//171// Font file access172//173174/**175* This method reads a table from the font. Note that in general,176* it only makes sense to call this method on an <code>LEFontInstance</code>177* which represents a physical font - i.e. one which has been returned by178* <code>getSubFont()</code>. This is because each subfont in a composite font179* will have different tables, and there's no way to know which subfont to access.180*181* Subclasses which represent composite fonts should always return <code>NULL</code>.182*183* Note that implementing this function does not allow for range checking.184* Subclasses that desire the safety of range checking must implement the185* variation which has a length parameter.186*187* @param tableTag - the four byte table tag. (e.g. 'cmap')188*189* @return the address of the table in memory, or <code>NULL</code>190* if the table doesn't exist.191*192* @stable ICU 2.8193*/194virtual const void *getFontTable(LETag tableTag) const = 0;195196/**197* This method reads a table from the font. Note that in general,198* it only makes sense to call this method on an <code>LEFontInstance</code>199* which represents a physical font - i.e. one which has been returned by200* <code>getSubFont()</code>. This is because each subfont in a composite font201* will have different tables, and there's no way to know which subfont to access.202*203* Subclasses which represent composite fonts should always return <code>NULL</code>.204*205* This version sets a length, for range checking.206* Note that range checking can only be accomplished if this function is207* implemented in subclasses.208*209* @param tableTag - the four byte table tag. (e.g. 'cmap')210* @param length - ignored on entry, on exit will be the length of the table if known, or -1 if unknown.211* @return the address of the table in memory, or <code>NULL</code>212* if the table doesn't exist.213* @internal214*/215virtual const void* getFontTable(LETag tableTag, size_t &length) const { length=-1; return getFontTable(tableTag); } /* -1 = unknown length */216217virtual void *getKernPairs() const = 0;218virtual void setKernPairs(void *pairs) const = 0;219220/**221* This method is used to determine if the font can222* render the given character. This can usually be done223* by looking the character up in the font's character224* to glyph mapping.225*226* The default implementation of this method will return227* <code>TRUE</code> if <code>mapCharToGlyph(ch)</code>228* returns a non-zero value.229*230* @param ch - the character to be tested231*232* @return <code>TRUE</code> if the font can render ch.233*234* @stable ICU 3.2235*/236virtual le_bool canDisplay(LEUnicode32 ch) const;237238/**239* This method returns the number of design units in240* the font's EM square.241*242* @return the number of design units pre EM.243*244* @stable ICU 2.8245*/246virtual le_int32 getUnitsPerEM() const = 0;247248/**249* This method maps an array of character codes to an array of glyph250* indices, using the font's character to glyph map.251*252* The default implementation iterates over all of the characters and calls253* <code>mapCharToGlyph(ch, mapper)</code> on each one. It also handles surrogate254* characters, storing the glyph ID for the high surrogate, and a deleted glyph (0xFFFF)255* for the low surrogate.256*257* Most sublcasses will not need to implement this method.258*259* @param chars - the character array260* @param offset - the index of the first character261* @param count - the number of characters262* @param reverse - if <code>TRUE</code>, store the glyph indices in reverse order.263* @param mapper - the character mapper.264* @param filterZeroWidth - <code>TRUE</code> if ZWJ / ZWNJ characters should map to a glyph w/ no contours.265* @param glyphStorage - the object which contains the output glyph array266*267* @see LECharMapper268*269* @stable ICU 3.6270*/271virtual void mapCharsToGlyphs(const LEUnicode chars[], le_int32 offset, le_int32 count, le_bool reverse, const LECharMapper *mapper, le_bool filterZeroWidth, LEGlyphStorage &glyphStorage) const;272273/**274* This method maps a single character to a glyph index, using the275* font's character to glyph map. The default implementation of this276* method calls the mapper, and then calls <code>mapCharToGlyph(mappedCh)</code>.277*278* @param ch - the character279* @param mapper - the character mapper280* @param filterZeroWidth - <code>TRUE</code> if ZWJ / ZWNJ characters should map to a glyph w/ no contours.281*282* @return the glyph index283*284* @see LECharMapper285*286* @stable ICU 3.6287*/288virtual LEGlyphID mapCharToGlyph(LEUnicode32 ch, const LECharMapper *mapper, le_bool filterZeroWidth) const;289290/**291* This method maps a single character to a glyph index, using the292* font's character to glyph map. The default implementation of this293* method calls the mapper, and then calls <code>mapCharToGlyph(mappedCh)</code>.294*295* @param ch - the character296* @param mapper - the character mapper297*298* @return the glyph index299*300* @see LECharMapper301*302* @stable ICU 3.2303*/304virtual LEGlyphID mapCharToGlyph(LEUnicode32 ch, const LECharMapper *mapper) const;305306/**307* This method maps a single character to a glyph index, using the308* font's character to glyph map. There is no default implementation309* of this method because it requires information about the platform310* font implementation.311*312* @param ch - the character313*314* @return the glyph index315*316* @stable ICU 3.2317*/318virtual LEGlyphID mapCharToGlyph(LEUnicode32 ch) const = 0;319320//321// Metrics322//323324/**325* This method gets the X and Y advance of a particular glyph, in pixels.326*327* @param glyph - the glyph index328* @param advance - the X and Y pixel values will be stored here329*330* @stable ICU 3.2331*/332virtual void getGlyphAdvance(LEGlyphID glyph, LEPoint &advance) const = 0;333334virtual void getKerningAdjustment(LEPoint &adjustment) const = 0;335336/**337* This method gets the hinted X and Y pixel coordinates of a particular338* point in the outline of the given glyph.339*340* @param glyph - the glyph index341* @param pointNumber - the number of the point342* @param point - the point's X and Y pixel values will be stored here343*344* @return <code>TRUE</code> if the point coordinates could be stored.345*346* @stable ICU 2.8347*/348virtual le_bool getGlyphPoint(LEGlyphID glyph, le_int32 pointNumber, LEPoint &point) const = 0;349350/**351* This method returns the width of the font's EM square352* in pixels.353*354* @return the pixel width of the EM square355*356* @stable ICU 2.8357*/358virtual float getXPixelsPerEm() const = 0;359360/**361* This method returns the height of the font's EM square362* in pixels.363*364* @return the pixel height of the EM square365*366* @stable ICU 2.8367*/368virtual float getYPixelsPerEm() const = 0;369370/**371* This method converts font design units in the372* X direction to points.373*374* @param xUnits - design units in the X direction375*376* @return points in the X direction377*378* @stable ICU 3.2379*/380virtual float xUnitsToPoints(float xUnits) const;381382/**383* This method converts font design units in the384* Y direction to points.385*386* @param yUnits - design units in the Y direction387*388* @return points in the Y direction389*390* @stable ICU 3.2391*/392virtual float yUnitsToPoints(float yUnits) const;393394/**395* This method converts font design units to points.396*397* @param units - X and Y design units398* @param points - set to X and Y points399*400* @stable ICU 3.2401*/402virtual void unitsToPoints(LEPoint &units, LEPoint &points) const;403404/**405* This method converts pixels in the406* X direction to font design units.407*408* @param xPixels - pixels in the X direction409*410* @return font design units in the X direction411*412* @stable ICU 3.2413*/414virtual float xPixelsToUnits(float xPixels) const;415416/**417* This method converts pixels in the418* Y direction to font design units.419*420* @param yPixels - pixels in the Y direction421*422* @return font design units in the Y direction423*424* @stable ICU 3.2425*/426virtual float yPixelsToUnits(float yPixels) const;427428/**429* This method converts pixels to font design units.430*431* @param pixels - X and Y pixel432* @param units - set to X and Y font design units433*434* @stable ICU 3.2435*/436virtual void pixelsToUnits(LEPoint &pixels, LEPoint &units) const;437438/**439* Get the X scale factor from the font's transform. The default440* implementation of <code>transformFunits()</code> will call this method.441*442* @return the X scale factor.443*444*445* @see transformFunits446*447* @stable ICU 3.2448*/449virtual float getScaleFactorX() const = 0;450451/**452* Get the Y scale factor from the font's transform. The default453* implementation of <code>transformFunits()</code> will call this method.454*455* @return the Yscale factor.456*457* @see transformFunits458*459* @stable ICU 3.2460*/461virtual float getScaleFactorY() const = 0;462463/**464* This method transforms an X, Y point in font design units to a465* pixel coordinate, applying the font's transform. The default466* implementation of this method calls <code>getScaleFactorX()</code>467* and <code>getScaleFactorY()</code>.468*469* @param xFunits - the X coordinate in font design units470* @param yFunits - the Y coordinate in font design units471* @param pixels - the tranformed co-ordinate in pixels472*473* @see getScaleFactorX474* @see getScaleFactorY475*476* @stable ICU 3.2477*/478virtual void transformFunits(float xFunits, float yFunits, LEPoint &pixels) const;479480/**481* This is a convenience method used to convert482* values in a 16.16 fixed point format to floating point.483*484* @param fixed - the fixed point value485*486* @return the floating point value487*488* @stable ICU 2.8489*/490static inline float fixedToFloat(le_int32 fixed);491492/**493* This is a convenience method used to convert494* floating point values to 16.16 fixed point format.495*496* @param theFloat - the floating point value497*498* @return the fixed point value499*500* @stable ICU 2.8501*/502static inline le_int32 floatToFixed(float theFloat);503504//505// These methods won't ever be called by the LayoutEngine,506// but are useful for clients of <code>LEFontInstance</code> who507// need to render text.508//509510/**511* Get the font's ascent.512*513* @return the font's ascent, in points. This value514* will always be positive.515*516* @stable ICU 3.2517*/518virtual le_int32 getAscent() const = 0;519520/**521* Get the font's descent.522*523* @return the font's descent, in points. This value524* will always be positive.525*526* @stable ICU 3.2527*/528virtual le_int32 getDescent() const = 0;529530/**531* Get the font's leading.532*533* @return the font's leading, in points. This value534* will always be positive.535*536* @stable ICU 3.2537*/538virtual le_int32 getLeading() const = 0;539540/**541* Get the line height required to display text in542* this font. The default implementation of this method543* returns the sum of the ascent, descent, and leading.544*545* @return the line height, in points. This vaule will546* always be positive.547*548* @stable ICU 3.2549*/550virtual le_int32 getLineHeight() const;551552/**553* ICU "poor man's RTTI", returns a UClassID for the actual class.554*555* @stable ICU 3.2556*/557virtual UClassID getDynamicClassID() const;558559/**560* ICU "poor man's RTTI", returns a UClassID for this class.561*562* @stable ICU 3.2563*/564static UClassID getStaticClassID();565566};567568inline float LEFontInstance::fixedToFloat(le_int32 fixed)569{570return (float) (fixed / 65536.0);571}572573inline le_int32 LEFontInstance::floatToFixed(float theFloat)574{575return (le_int32) (theFloat * 65536.0);576}577578U_NAMESPACE_END579#endif580581582