1ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
2ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/*
3ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *******************************************************************************
4ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *
5ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *   Copyright (C) 1999-2006, International Business Machines
6ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *   Corporation and others.  All Rights Reserved.
7ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *
8ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *******************************************************************************
9ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *   file name:  GnomeFontInstance.h
10ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *
11ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *   created on: 08/30/2001
12ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *   created by: Eric R. Mader
13ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */
14ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
15ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#ifndef __GNOMEFONTINSTANCE_H
16ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define __GNOMEFONTINSTANCE_H
17ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
18ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include <gnome.h>
19ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include <ft2build.h>
20ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include FT_FREETYPE_H
21ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include FT_GLYPH_H
22ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include <cairo.h>
23ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
24ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "layout/LETypes.h"
25ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "layout/LEFontInstance.h"
26ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
27ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "RenderingSurface.h"
28ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "FontTableCache.h"
29ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "cmaps.h"
30ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
31ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruclass GnomeSurface : public RenderingSurface
32ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
33ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querupublic:
34ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    GnomeSurface(GtkWidget *theWidget);
35ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    virtual ~GnomeSurface();
36ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
37ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    virtual void drawGlyphs(const LEFontInstance *font, const LEGlyphID *glyphs, le_int32 count,
38ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        const float *positions, le_int32 x, le_int32 y, le_int32 width, le_int32 height);
39ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
40ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    GtkWidget *getWidget() const;
41ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    void setWidget(GtkWidget *theWidget);
42ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
43ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruprivate:
44ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    GtkWidget *fWidget;
45ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    cairo_t   *fCairo;
46ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru};
47ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
48ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruclass GnomeFontInstance : public LEFontInstance, protected FontTableCache
49ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
50ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru protected:
51ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    FT_Face fFace;
52ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru//  FT_Glyph fGlyph;
53ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
54ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    cairo_font_face_t *fCairoFace;
55ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
56ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    le_int32 fPointSize;
57ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    le_int32 fUnitsPerEM;
58ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    le_int32 fAscent;
59ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    le_int32 fDescent;
60ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    le_int32 fLeading;
61ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
62ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    float fDeviceScaleX;
63ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    float fDeviceScaleY;
64ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
65ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    CMAPMapper *fMapper;
66ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
67ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    virtual const void *readFontTable(LETag tableTag) const;
68ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
69ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    virtual LEErrorCode initMapper();
70ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
71ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru public:
72ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    GnomeFontInstance(FT_Library engine, const char *fontPathName, le_int16 pointSize, LEErrorCode &status);
73ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
74ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    virtual ~GnomeFontInstance();
75ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
76ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    virtual const void *getFontTable(LETag tableTag) const;
77ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
78ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    virtual le_int32 getUnitsPerEM() const;
79ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
80ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    virtual le_int32 getAscent() const;
81ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
82ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    virtual le_int32 getDescent() const;
83ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
84ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    virtual le_int32 getLeading() const;
85ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
86ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    virtual LEGlyphID mapCharToGlyph(LEUnicode32 ch) const;
87ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
88ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    virtual void getGlyphAdvance(LEGlyphID glyph, LEPoint &advance) const;
89ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
90ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    virtual le_bool getGlyphPoint(LEGlyphID glyph, le_int32 pointNumber, LEPoint &point) const;
91ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
92ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    float getXPixelsPerEm() const;
93ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
94ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    float getYPixelsPerEm() const;
95ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
96ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    float getScaleFactorX() const;
97ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
98ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    float getScaleFactorY() const;
99ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    void rasterizeGlyphs(cairo_t *cairo, const LEGlyphID *glyphs, le_int32 glyphCount, const float *positions,
101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru				   le_int32 x, le_int32 y) const;
102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru};
103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruinline GtkWidget *GnomeSurface::getWidget() const
105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return fWidget;
107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruinline void GnomeSurface::setWidget(GtkWidget *theWidget)
110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
111ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    fWidget = theWidget;
112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
114ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/*
115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruinline FT_Instance GnomeFontInstance::getFont() const
116ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
117ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return fInstance;
118ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
119ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*/
120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
121ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruinline le_int32 GnomeFontInstance::getUnitsPerEM() const
122ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
123ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return fUnitsPerEM;
124ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
125ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
126ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruinline le_int32 GnomeFontInstance::getAscent() const
127ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
128ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return fAscent;
129ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
130ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
131ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruinline le_int32 GnomeFontInstance::getDescent() const
132ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
133ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return fDescent;
134ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
135ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
136ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruinline le_int32 GnomeFontInstance::getLeading() const
137ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
138ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return fLeading;
139ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
140ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
141ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruinline LEGlyphID GnomeFontInstance::mapCharToGlyph(LEUnicode32 ch) const
142ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
143ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return fMapper->unicodeToGlyph(ch);
144ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
145ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
146ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruinline float GnomeFontInstance::getXPixelsPerEm() const
147ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
148ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return (float) fPointSize;
149ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
150ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
151ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruinline float GnomeFontInstance::getYPixelsPerEm() const
152ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
153ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return  (float) fPointSize;
154ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
155ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
156ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruinline float GnomeFontInstance::getScaleFactorX() const
157ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
158ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return fDeviceScaleX;
159ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
160ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
161ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruinline float GnomeFontInstance::getScaleFactorY() const
162ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
163ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return fDeviceScaleY;
164ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
165ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
166ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
167