1ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* 2ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ******************************************************************************* 3ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 4ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Copyright (C) 1999-2007, International Business Machines 5ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Corporation and others. All Rights Reserved. 6ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 7ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ******************************************************************************* 8ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * file name: LEFontInstance.cpp 9ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 10ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * created on: 02/06/2003 11ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * created by: Eric R. Mader 12ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 13ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 14ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "LETypes.h" 15ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "LEScripts.h" 16ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "LEFontInstance.h" 17ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "LEGlyphStorage.h" 18ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 19ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruU_NAMESPACE_BEGIN 20ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 21ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUOBJECT_DEFINE_RTTI_IMPLEMENTATION(LEFontInstance) 22ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 23ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruLECharMapper::~LECharMapper() 24ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 25ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // nothing to do. 26ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 27ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 28ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruLEFontInstance::~LEFontInstance() 29ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 30ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru // nothing to do 31ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 32ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 33ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruconst LEFontInstance *LEFontInstance::getSubFont(const LEUnicode chars[], le_int32 *offset, le_int32 limit, 34ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru le_int32 script, LEErrorCode &success) const 35ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 36ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (LE_FAILURE(success)) { 37ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return NULL; 38ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 39ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 40ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (chars == NULL || *offset < 0 || limit < 0 || *offset >= limit || script < 0 || script >= scriptCodeCount) { 41ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru success = LE_ILLEGAL_ARGUMENT_ERROR; 42ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return NULL; 43ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 44ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 45ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *offset = limit; 46ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return this; 47ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 48ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 49ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid LEFontInstance::mapCharsToGlyphs(const LEUnicode chars[], le_int32 offset, le_int32 count, 50ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru le_bool reverse, const LECharMapper *mapper, le_bool filterZeroWidth, LEGlyphStorage &glyphStorage) const 51ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 52ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru le_int32 i, out = 0, dir = 1; 53ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 54ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (reverse) { 55ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru out = count - 1; 56ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru dir = -1; 57ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 58ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 59ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (i = offset; i < offset + count; i += 1, out += dir) { 60ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru LEUnicode16 high = chars[i]; 61ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru LEUnicode32 code = high; 62ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 63ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (i < offset + count - 1 && high >= 0xD800 && high <= 0xDBFF) { 64ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru LEUnicode16 low = chars[i + 1]; 65ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 66ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (low >= 0xDC00 && low <= 0xDFFF) { 67ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru code = (high - 0xD800) * 0x400 + low - 0xDC00 + 0x10000; 68ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 69ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 70ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 71ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru glyphStorage[out] = mapCharToGlyph(code, mapper, filterZeroWidth); 72ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 73ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (code >= 0x10000) { 74ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru i += 1; 75ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru glyphStorage[out += dir] = 0xFFFF; 76ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 77ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 78ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 79ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 80ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruLEGlyphID LEFontInstance::mapCharToGlyph(LEUnicode32 ch, const LECharMapper *mapper) const 81ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 82ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return mapCharToGlyph(ch, mapper, TRUE); 83ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 84ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 85ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruLEGlyphID LEFontInstance::mapCharToGlyph(LEUnicode32 ch, const LECharMapper *mapper, le_bool filterZeroWidth) const 86ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 87ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru LEUnicode32 mappedChar = mapper->mapChar(ch); 88ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 89ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (mappedChar == 0xFFFE || mappedChar == 0xFFFF) { 90ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return 0xFFFF; 91ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 92ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 93ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (filterZeroWidth && (mappedChar == 0x200C || mappedChar == 0x200D)) { 94ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return canDisplay(mappedChar)? 0x0001 : 0xFFFF; 95ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 96ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 97ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return mapCharToGlyph(mappedChar); 98ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 99ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querule_bool LEFontInstance::canDisplay(LEUnicode32 ch) const 101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return LE_GET_GLYPH(mapCharToGlyph(ch)) != 0; 103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querufloat LEFontInstance::xUnitsToPoints(float xUnits) const 106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return (xUnits * getXPixelsPerEm()) / (float) getUnitsPerEM(); 108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querufloat LEFontInstance::yUnitsToPoints(float yUnits) const 111ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return (yUnits * getYPixelsPerEm()) / (float) getUnitsPerEM(); 113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 114ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid LEFontInstance::unitsToPoints(LEPoint &units, LEPoint &points) const 116ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 117ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru points.fX = xUnitsToPoints(units.fX); 118ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru points.fY = yUnitsToPoints(units.fY); 119ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 121ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querufloat LEFontInstance::xPixelsToUnits(float xPixels) const 122ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 123ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return (xPixels * getUnitsPerEM()) / (float) getXPixelsPerEm(); 124ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 125ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 126ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querufloat LEFontInstance::yPixelsToUnits(float yPixels) const 127ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 128ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return (yPixels * getUnitsPerEM()) / (float) getYPixelsPerEm(); 129ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 130ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 131ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid LEFontInstance::pixelsToUnits(LEPoint &pixels, LEPoint &units) const 132ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 133ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru units.fX = xPixelsToUnits(pixels.fX); 134ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru units.fY = yPixelsToUnits(pixels.fY); 135ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 136ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 137ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid LEFontInstance::transformFunits(float xFunits, float yFunits, LEPoint &pixels) const 138ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 139ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru pixels.fX = xUnitsToPoints(xFunits) * getScaleFactorX(); 140ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru pixels.fY = yUnitsToPoints(yFunits) * getScaleFactorY(); 141ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 142ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 143ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querule_int32 LEFontInstance::getLineHeight() const 144ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 145ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return getAscent() + getDescent() + getLeading(); 146ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 147ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 148ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruU_NAMESPACE_END 149ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 150