CairoFontEngine.h 3.62 KB
Newer Older
Kristian Høgsberg's avatar
Kristian Høgsberg committed
1 2 3 4
//========================================================================
//
// CairoFontEngine.h
//
5 6 7 8 9 10 11 12 13
// Copyright 2003 Glyph & Cog, LLC
// Copyright 2004 Red Hat, Inc
//
//========================================================================

//========================================================================
//
// Modified under the Poppler project - http://poppler.freedesktop.org
//
14 15 16
// All changes made under the Poppler project to this file are licensed
// under GPL version 2 or later
//
17
// Copyright (C) 2005, 2006 Kristian Høgsberg <krh@redhat.com>
18
// Copyright (C) 2005, 2018 Albert Astals Cid <aacid@kde.org>
19
// Copyright (C) 2006, 2007 Jeff Muizelaar <jeff@infidigm.net>
20
// Copyright (C) 2006, 2010 Carlos Garcia Campos <carlosgc@gnome.org>
21
// Copyright (C) 2008, 2017 Adrian Johnson <ajohnson@redneon.com>
22
// Copyright (C) 2013 Thomas Freitag <Thomas.Freitag@alfa.de>
23 24 25 26
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
//
Kristian Høgsberg's avatar
Kristian Høgsberg committed
27 28 29 30 31 32 33 34 35
//========================================================================

#ifndef CAIROFONTENGINE_H
#define CAIROFONTENGINE_H

#ifdef USE_GCC_PRAGMAS
#pragma interface
#endif

36
#include "poppler-config.h"
Kristian Høgsberg's avatar
Kristian Høgsberg committed
37 38 39 40
#include "goo/gtypes.h"
#include <cairo-ft.h>

#include "GfxFont.h"
41
#include "PDFDoc.h"
Kristian Høgsberg's avatar
Kristian Høgsberg committed
42

43 44
class CairoFontEngine;

Kristian Høgsberg's avatar
Kristian Høgsberg committed
45 46
class CairoFont {
public:
Adrian Johnson's avatar
Adrian Johnson committed
47
  CairoFont(Ref ref,
48
	    cairo_font_face_t *face,
49
	    int *codeToGID,
50
	    Guint codeToGIDLen,
51 52
	    GBool substitute,
	    GBool printing);
Adrian Johnson's avatar
Adrian Johnson committed
53
  virtual ~CairoFont();
54 55
  CairoFont(const CairoFont &) = delete;
  CairoFont& operator=(const CairoFont &other) = delete;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
56

57
  virtual GBool matches(Ref &other, GBool printing);
58
  cairo_font_face_t *getFontFace(void);
59
  unsigned long getGlyph(CharCode code, Unicode *u, int uLen);
60 61 62
  double getSubstitutionCorrection(GfxFont *gfxFont);

  GBool isSubstitute() { return substitute; }
Adrian Johnson's avatar
Adrian Johnson committed
63
protected:
Kristian Høgsberg's avatar
Kristian Høgsberg committed
64
  Ref ref;
65
  cairo_font_face_t *cairo_font_face;
66

67
  int *codeToGID;
68
  Guint codeToGIDLen;
69 70

  GBool substitute;
71
  GBool printing;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
72 73 74 75
};

//------------------------------------------------------------------------

Adrian Johnson's avatar
Adrian Johnson committed
76 77 78
class CairoFreeTypeFont : public CairoFont {
public:
  static CairoFreeTypeFont *create(GfxFont *gfxFont, XRef *xref, FT_Library lib, GBool useCIDs);
Albert Astals Cid's avatar
Albert Astals Cid committed
79
  ~CairoFreeTypeFont();
Adrian Johnson's avatar
Adrian Johnson committed
80 81

private:
82
  CairoFreeTypeFont(Ref ref, cairo_font_face_t *cairo_font_face,
83
	    int *codeToGID, Guint codeToGIDLen, GBool substitute);
Adrian Johnson's avatar
Adrian Johnson committed
84 85 86 87
};

//------------------------------------------------------------------------

88 89
class CairoType3Font : public CairoFont {
public:
90 91
  static CairoType3Font *create(GfxFont *gfxFont, PDFDoc *doc,
				CairoFontEngine *fontEngine,
92
				GBool printing, XRef *xref);
Albert Astals Cid's avatar
Albert Astals Cid committed
93
  ~CairoType3Font();
94

Albert Astals Cid's avatar
Albert Astals Cid committed
95
  GBool matches(Ref &other, GBool printing) override;
96

97
private:
98
  CairoType3Font(Ref ref, PDFDoc *doc,
99
		 cairo_font_face_t *cairo_font_face,
100
		 int *codeToGID, Guint codeToGIDLen,
101
		 GBool printing, XRef *xref);
102
  PDFDoc *doc;
103 104 105 106
};

//------------------------------------------------------------------------

107
#define cairoFontCacheSize 64
Kristian Høgsberg's avatar
Kristian Høgsberg committed
108 109 110 111 112 113 114 115 116 117 118

//------------------------------------------------------------------------
// CairoFontEngine
//------------------------------------------------------------------------

class CairoFontEngine {
public:

  // Create a font engine.
  CairoFontEngine(FT_Library libA);
  ~CairoFontEngine();
119 120
  CairoFontEngine(const CairoFontEngine &) = delete;
  CairoFontEngine& operator=(const CairoFontEngine &other) = delete;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
121

122
  CairoFont *getFont(GfxFont *gfxFont, PDFDoc *doc, GBool printing, XRef *xref);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
123 124 125 126

private:
  CairoFont *fontCache[cairoFontCacheSize];
  FT_Library lib;
127
  GBool useCIDs;
128
#ifdef MULTITHREADED
129 130
  GooMutex mutex;
#endif
Kristian Høgsberg's avatar
Kristian Høgsberg committed
131 132 133
};

#endif