~ubuntu-branches/ubuntu/gutsy/icu/gutsy-updates

« back to all changes in this revision

Viewing changes to source/test/letest/PortableFontInstance.h

  • Committer: Package Import Robot
  • Author(s): Jay Berkenbilt
  • Date: 2005-11-19 11:29:31 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20051119112931-vcizkrp10tli4enw
Tags: 3.4-3
Explicitly build with g++ 3.4.  The current ICU fails its test suite
with 4.0 but not with 3.4.  Future versions should work properly with
4.0.

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:  PortableFontInstance.h
10
 
 *
11
 
 *   created on: 11/12/1999
12
 
 *   created by: Eric R. Mader
13
 
 */
14
 
 
15
 
#ifndef __PORTABLEFONTINSTANCE_H
16
 
#define __PORTABLEFONTINSTANCE_H
17
 
 
18
 
#include <stdio.h>
19
 
 
20
 
#include "LETypes.h"
21
 
#include "LEFontInstance.h"
22
 
 
23
 
#include "sfnt.h"
24
 
#include "cmaps.h"
25
 
 
26
 
#define TABLE_CACHE_INIT 5
27
 
#define TABLE_CACHE_GROW 5
28
 
 
29
 
struct TableCacheEntry
30
 
{
31
 
    LETag tag;
32
 
    void *table;
33
 
};
34
 
 
35
 
enum PFIErrorCode {
36
 
    PFI_NO_ERROR = 0,
37
 
 
38
 
    PFI_FONT_FILE_NOT_FOUND_ERROR = 1,
39
 
    PFI_MISSING_FONT_TABLE_ERROR  = 2,
40
 
    PFI_OUT_OF_MEMORY_ERROR       = 3
41
 
};
42
 
 
43
 
#ifndef XP_CPLUSPLUS
44
 
typedef enum PFIErrorCode PFIErrorCode;
45
 
#endif
46
 
 
47
 
class PortableFontInstance : public LEFontInstance
48
 
{
49
 
private:
50
 
    FILE *fFile;
51
 
 
52
 
    float fUnitsPerEM;
53
 
    float fPointSize;
54
 
 
55
 
    const SFNTDirectory *fDirectory;
56
 
    le_uint16 fDirPower;
57
 
    le_uint16 fDirExtra;
58
 
 
59
 
    TableCacheEntry *fTableCache;
60
 
    le_int32 fTableCacheCurr;
61
 
    le_int32 fTableCacheSize;
62
 
 
63
 
    CMAPMapper *fCMAPMapper;
64
 
 
65
 
    const HMTXTable *fHMTXTable;
66
 
    le_uint16 fNumGlyphs;
67
 
    le_uint16 fNumLongHorMetrics;
68
 
 
69
 
    static le_int8 highBit(le_int32 value);
70
 
 
71
 
    PFIErrorCode PortableFontInstance::initFontTableCache();
72
 
    void PortableFontInstance::flushFontTableCache();
73
 
 
74
 
    const DirectoryEntry *findTable(LETag tag) const;
75
 
    const void *readTable(LETag tag, le_uint32 *length) const;
76
 
    void deleteTable(const void *table) const;
77
 
 
78
 
    CMAPMapper *PortableFontInstance::findUnicodeMapper();
79
 
 
80
 
public:
81
 
    PortableFontInstance(char *fileName, float pointSize, PFIErrorCode &status);
82
 
 
83
 
    virtual ~PortableFontInstance();
84
 
 
85
 
    virtual const void *getFontTable(LETag tableTag) const;
86
 
 
87
 
    virtual le_bool canDisplay(LEUnicode32 ch) const
88
 
    {
89
 
        return (le_bool) fCMAPMapper->unicodeToGlyph(ch) != 0;
90
 
    };
91
 
 
92
 
    virtual le_int32 getUnitsPerEM() const
93
 
    {
94
 
        return (le_int32) fUnitsPerEM;
95
 
    };
96
 
 
97
 
    virtual le_int32 getLineHeight() const
98
 
    {
99
 
        // this is a cheap hack!!
100
 
    return (le_int32) fPointSize;
101
 
    };
102
 
 
103
 
    virtual void mapCharsToGlyphs(const LEUnicode chars[], le_int32 offset, le_int32 count, le_bool reverse, const LECharMapper *mapper, LEGlyphID glyphs[]) const;
104
 
 
105
 
    virtual LEGlyphID mapCharToGlyph(LEUnicode32 ch, const LECharMapper *mapper) const;
106
 
 
107
 
    virtual le_int32 getName(le_uint16 platformID, le_uint16 scriptID, le_uint16 languageID, le_uint16 nameID, LEUnicode *name) const
108
 
    {
109
 
        // This is only used for CDAC fonts, and we'll have to loose that support anyhow...
110
 
        //return (le_int32) fFontObject->getName(platformID, scriptID, languageID, nameID, name);
111
 
        if (name != NULL) {
112
 
            *name = 0;
113
 
        }
114
 
 
115
 
        return 0;
116
 
    };
117
 
 
118
 
    virtual void getGlyphAdvance(LEGlyphID glyph, LEPoint &advance) const;
119
 
 
120
 
    virtual le_bool getGlyphPoint(LEGlyphID glyph, le_int32 pointNumber, LEPoint &point) const;
121
 
 
122
 
    float getXPixelsPerEm() const
123
 
    {
124
 
        return fPointSize;
125
 
    };
126
 
 
127
 
    float getYPixelsPerEm() const
128
 
    {
129
 
        return fPointSize;
130
 
    };
131
 
 
132
 
    float xUnitsToPoints(float xUnits) const
133
 
    {
134
 
        return (xUnits * fPointSize) / fUnitsPerEM;
135
 
    };
136
 
 
137
 
    float yUnitsToPoints(float yUnits) const
138
 
    {
139
 
        return (yUnits * fPointSize) / fUnitsPerEM;
140
 
    };
141
 
 
142
 
    void unitsToPoints(LEPoint &units, LEPoint &points) const
143
 
    {
144
 
        points.fX = xUnitsToPoints(units.fX);
145
 
        points.fY = yUnitsToPoints(units.fY);
146
 
    }
147
 
 
148
 
    float xPixelsToUnits(float xPixels) const
149
 
    {
150
 
        return (xPixels * fUnitsPerEM) / fPointSize;
151
 
    };
152
 
 
153
 
    float yPixelsToUnits(float yPixels) const
154
 
    {
155
 
        return (yPixels * fUnitsPerEM) / fPointSize;
156
 
    };
157
 
 
158
 
    void pixelsToUnits(LEPoint &pixels, LEPoint &units) const
159
 
    {
160
 
        units.fX = xPixelsToUnits(pixels.fX);
161
 
        units.fY = yPixelsToUnits(pixels.fY);
162
 
    };
163
 
 
164
 
    void transformFunits(float xFunits, float yFunits, LEPoint &pixels) const;
165
 
};
166
 
 
167
 
#endif