~ubuntu-branches/ubuntu/precise/ipe/precise

« back to all changes in this revision

Viewing changes to src/ipemodel/ipeftfont_p.h

  • Committer: Bazaar Package Importer
  • Author(s): Steve M. Robbins
  • Date: 2004-06-08 00:44:02 UTC
  • Revision ID: james.westby@ubuntu.com-20040608004402-72yu51xlh7vt6p9m
Tags: upstream-6.0pre16
ImportĀ upstreamĀ versionĀ 6.0pre16

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- C++ -*-
 
2
// --------------------------------------------------------------------
 
3
// A wrapper for the FreeType font rasterizer.
 
4
//
 
5
// Copyright 2001-2002 Glyph & Cog, LLC
 
6
// Modified by Otfried Cheong
 
7
// --------------------------------------------------------------------
 
8
/*
 
9
 
 
10
    This file is part of the extensible drawing editor Ipe.
 
11
    Copyright (C) 1993-2004  Otfried Cheong
 
12
 
 
13
    Ipe is free software; you can redistribute it and/or modify it
 
14
    under the terms of the GNU General Public License as published by
 
15
    the Free Software Foundation; either version 2 of the License, or
 
16
    (at your option) any later version.
 
17
 
 
18
    As a special exception, you have permission to link Ipe with the
 
19
    CGAL library and distribute executables, as long as you follow the
 
20
    requirements of the Gnu General Public License in regard to all of
 
21
    the software in the executable aside from CGAL.
 
22
 
 
23
    Ipe is distributed in the hope that it will be useful, but WITHOUT
 
24
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 
25
    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
 
26
    License for more details.
 
27
 
 
28
    You should have received a copy of the GNU General Public License
 
29
    along with Ipe; if not, you can find it at
 
30
    "http://www.gnu.org/copyleft/gpl.html", or write to the Free
 
31
    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
32
 
 
33
*/
 
34
 
 
35
#ifndef FTFONT_H
 
36
#define FTFONT_H
 
37
 
 
38
#include "ipepdflib_p.h"
 
39
 
 
40
#include <qcolor.h>
 
41
 
 
42
#include <ft2build.h>
 
43
#include FT_FREETYPE_H
 
44
 
 
45
//------------------------------------------------------------------------
 
46
 
 
47
class QPixmap;
 
48
 
 
49
class FTFontEngine {
 
50
public:
 
51
  FTFontEngine(bool aa);
 
52
  bool IsOk() { return iOk; }
 
53
  virtual ~FTFontEngine();
 
54
 
 
55
private:
 
56
  FT_Library iLib;
 
57
  bool iAa;
 
58
  bool iOk;
 
59
 
 
60
  friend class FTFace;
 
61
  friend class FTFont;
 
62
};
 
63
 
 
64
//------------------------------------------------------------------------
 
65
 
 
66
enum FTFontIndexMode {
 
67
  ftFontModeUnicode,
 
68
  ftFontModeCharCode,
 
69
  ftFontModeCharCodeOffset,
 
70
  ftFontModeCodeMap,
 
71
  ftFontModeCodeMapDirect,
 
72
  ftFontModeCIDToGIDMap,
 
73
  ftFontModeCFFCharset
 
74
};
 
75
 
 
76
class FTFace {
 
77
public:
 
78
  FTFace(Ref *id, FTFontEngine *engine, char *fontFileName);
 
79
  FTFace(Ref *id, FTFontEngine *engine,
 
80
         const char *buffer, int bufsize);
 
81
  ~FTFace();
 
82
 
 
83
  void SetMode(char **fontEnc, bool pdfFontHasEncoding, bool type1);
 
84
  void SetMode(Gushort *cidToGID, int cidToGIDLen);
 
85
  void SetMode();
 
86
 
 
87
  //! Check whether it was loaded okay.
 
88
  bool IsOk() { return iOk; }
 
89
 
 
90
  //! Does this font match the ID?
 
91
  bool IsID(Ref *id) const {return (iId.num == id->num &&
 
92
                                     iId.gen == id->gen);}
 
93
 
 
94
private:
 
95
  Ref iId;
 
96
  FTFontEngine *iEngine;
 
97
  FT_Face iFace;
 
98
  FTFontIndexMode iMode;
 
99
  int iCharMapOffset;
 
100
  Guint *iCodeMap;
 
101
  Gushort *iCidToGID;
 
102
  int iCidToGIDLen;
 
103
  bool iOk;
 
104
 
 
105
  friend class FTFont;
 
106
};
 
107
 
 
108
//------------------------------------------------------------------------
 
109
 
 
110
struct FTFontCacheTag {
 
111
  Gushort code;
 
112
  Gushort mru;                  // valid bit (0x8000) and MRU index
 
113
  int x, y, w, h;               // offset and size of glyph
 
114
};
 
115
 
 
116
class FTFont {
 
117
public:
 
118
  FTFont(const FTFace *face,
 
119
         double m11, double m12,
 
120
         double m21, double m22);
 
121
  ~FTFont();
 
122
 
 
123
  //! Was font created okay?
 
124
  bool IsOk() { return iOk; }
 
125
 
 
126
  //! Does this font match the ID and transform?
 
127
  bool Matches(Ref *id, double m11, double m12, double m21, double m22)
 
128
  { return iFace->IsID(id) && iM11 == m11 && iM12 == m12 &&
 
129
      iM21 == m21 && iM22 == m22; }
 
130
 
 
131
  bool DrawChar(QPixmap *pixmap, int x, int y,
 
132
                QRgb rgb, CharCode c, Unicode u);
 
133
 
 
134
private:
 
135
  Guchar *GetGlyphPixmap(CharCode c, Unicode u,
 
136
                         int *x, int *y, int *w, int *h);
 
137
  FT_UInt GetGlyphIndex(CharCode c, Unicode u);
 
138
 
 
139
 private:
 
140
  FTFace *iFace;
 
141
  double iM11, iM12, iM21, iM22;
 
142
  FT_Matrix iMatrix;
 
143
  int iGlyphW, iGlyphH;         // size of glyph pixmaps
 
144
  int iGlyphSize;               // size of glyph pixmaps, in bytes
 
145
  Guchar *iCache;               // glyph pixmap cache
 
146
  FTFontCacheTag *iCacheTags;   // cache tags, i.e., char codes
 
147
  int iCacheSets;               // number of sets in cache
 
148
  int iCacheAssoc;              // cache associativity (glyphs per set)
 
149
  bool iOk;
 
150
};
 
151
 
 
152
// --------------------------------------------------------------------
 
153
#endif