~ubuntu-branches/ubuntu/quantal/icu/quantal

« back to all changes in this revision

Viewing changes to source/samples/layout/RenderingFontInstance.h

  • Committer: Package Import Robot
  • Author(s): Yves Arrouye
  • Date: 2002-03-03 15:31:13 UTC
  • Revision ID: package-import@ubuntu.com-20020303153113-3ssceqlq45xbmbnc
Tags: upstream-2.0-2.1pre20020303
ImportĀ upstreamĀ versionĀ 2.0-2.1pre20020303

Show diffs side-by-side

added added

removed removed

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