1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
|
/*
*******************************************************************************
*
* Copyright (C) 1999-2001, International Business Machines
* Corporation and others. All Rights Reserved.
*
*******************************************************************************
* file name: RenderingFontInstance.h
*
* created on: 10/23/2001
* created by: Eric R. Mader
*/
#ifndef __RENDERINGFONTINSTANCE_H
#define __RENDERINGFONTINSTANCE_H
#include "LETypes.h"
#include "LEFontInstance.h"
#include "cmaps.h"
#define TABLE_CACHE_INIT 5
#define TABLE_CACHE_GROW 5
struct TableCacheEntry
{
LETag tag;
void *table;
};
enum RFIErrorCode {
RFI_NO_ERROR = 0,
RFI_ILLEGAL_ARGUMENT_ERROR = 1,
RFI_FONT_FILE_NOT_FOUND_ERROR = 2,
RFI_MISSING_FONT_TABLE_ERROR = 3,
RFI_OUT_OF_MEMORY_ERROR = 4
};
class RenderingFontInstance : public LEFontInstance
{
protected:
void *fSurface;
le_int32 fPointSize;
le_int32 fUnitsPerEM;
le_int32 fAscent;
le_int32 fDescent;
le_int32 fLeading;
float fDeviceScaleX;
float fDeviceScaleY;
TableCacheEntry *fTableCache;
le_int32 fTableCacheCurr;
le_int32 fTableCacheSize;
CMAPMapper *fMapper;
virtual RFIErrorCode initMapper();
virtual RFIErrorCode initFontTableCache();
virtual void flushFontTableCache();
virtual const void *readFontTable(LETag tableTag) const = 0;
public:
RenderingFontInstance(void *surface, le_int16 pointSize);
virtual ~RenderingFontInstance();
virtual const void *getFontTable(LETag tableTag) const;
virtual le_bool canDisplay(LEUnicode32 ch) const
{
return fMapper->unicodeToGlyph(ch) != 0;
};
virtual le_int32 getUnitsPerEM() const
{
return fUnitsPerEM;
};
virtual le_int32 getLineHeight() const
{
return getAscent() + getDescent() + getLeading();
};
virtual le_int32 getAscent() const
{
return fAscent;
};
virtual le_int32 getDescent() const
{
return fDescent;
};
virtual le_int32 getLeading() const
{
return fLeading;
};
virtual void mapCharsToGlyphs(const LEUnicode chars[], le_int32 offset, le_int32 count, le_bool reverse, const LECharMapper *mapper, LEGlyphID glyphs[]) const;
virtual LEGlyphID mapCharToGlyph(LEUnicode32 ch, const LECharMapper *mapper) const;
virtual le_int32 getName(le_uint16 platformID, le_uint16 scriptID, le_uint16 languageID, le_uint16 nameID, LEUnicode *name) const
{
// This is only used for CDAC fonts, and we'll have to loose that support anyhow...
//return (le_int32) fFontObject->getName(platformID, scriptID, languageID, nameID, name);
if (name != NULL) {
*name = 0;
}
return 0;
};
virtual void getGlyphAdvance(LEGlyphID glyph, LEPoint &advance) const = 0;
virtual le_bool getGlyphPoint(LEGlyphID glyph, le_int32 pointNumber, LEPoint &point) const = 0;
virtual const void setFont(void *surface) const
{
// default implementation is to ignore this
};
virtual void drawGlyphs(void *surface, LEGlyphID *glyphs, le_uint32 count, le_int32 *dx,
le_int32 x, le_int32 y, le_int32 width, le_int32 height) const = 0;
float getXPixelsPerEm() const
{
return (float) fPointSize;
};
float getYPixelsPerEm() const
{
return (float) fPointSize;
};
float xUnitsToPoints(float xUnits) const
{
return (xUnits * fPointSize) / (float) fUnitsPerEM;
};
float yUnitsToPoints(float yUnits) const
{
return (yUnits * fPointSize) / (float) fUnitsPerEM;
};
void unitsToPoints(LEPoint &units, LEPoint &points) const
{
points.fX = xUnitsToPoints(units.fX);
points.fY = yUnitsToPoints(units.fY);
}
float xPixelsToUnits(float xPixels) const
{
return (xPixels * fUnitsPerEM) / (float) fPointSize;
};
float yPixelsToUnits(float yPixels) const
{
return (yPixels * fUnitsPerEM) / (float) fPointSize;
};
void pixelsToUnits(LEPoint &pixels, LEPoint &units) const
{
units.fX = xPixelsToUnits(pixels.fX);
units.fY = yPixelsToUnits(pixels.fY);
};
void transformFunits(float xFunits, float yFunits, LEPoint &pixels) const
{
pixels.fX = xUnitsToPoints(xFunits) * fDeviceScaleX;
pixels.fY = yUnitsToPoints(yFunits) * fDeviceScaleY;
}
};
#endif
|