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

« back to all changes in this revision

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