CairoFontEngine.h 3.6 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>
Albert Astals Cid's avatar
Albert Astals Cid committed
20
// Copyright (C) 2006, 2010 Carlos Garcia Campos <carlosgc@gnome.org>
21
// Copyright (C) 2008, 2017 Adrian Johnson <ajohnson@redneon.com>
Thomas Freitag's avatar
Thomas Freitag committed
22
// Copyright (C) 2013 Thomas Freitag <Thomas.Freitag@alfa.de>
Albert Astals Cid's avatar
Albert Astals Cid committed
23
// Copyright (C) 2018 Adam Reichold <adam.reichold@t-online.de>
24 25 26 27
//
// 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
28 29 30 31 32
//========================================================================

#ifndef CAIROFONTENGINE_H
#define CAIROFONTENGINE_H

33 34
#include <mutex>

Thomas Freitag's avatar
Thomas Freitag committed
35
#include "poppler-config.h"
Kristian Høgsberg's avatar
Kristian Høgsberg committed
36 37 38
#include <cairo-ft.h>

#include "GfxFont.h"
39
#include "PDFDoc.h"
Kristian Høgsberg's avatar
Kristian Høgsberg committed
40

41 42
class CairoFontEngine;

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

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

60
  bool isSubstitute() { return substitute; }
Adrian Johnson's avatar
Adrian Johnson committed
61
protected:
Kristian Høgsberg's avatar
Kristian Høgsberg committed
62
  Ref ref;
63
  cairo_font_face_t *cairo_font_face;
64

65
  int *codeToGID;
66
  unsigned int codeToGIDLen;
67

68 69
  bool substitute;
  bool printing;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
70 71 72 73
};

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

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

private:
80
  CairoFreeTypeFont(Ref ref, cairo_font_face_t *cairo_font_face,
81
	    int *codeToGID, unsigned int codeToGIDLen, bool substitute);
Adrian Johnson's avatar
Adrian Johnson committed
82 83 84 85
};

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

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

93
  bool matches(Ref &other, bool printing) override;
94

95
private:
96
  CairoType3Font(Ref ref,
97
		 cairo_font_face_t *cairo_font_face,
98
		 int *codeToGID, unsigned int codeToGIDLen,
99
		 bool printing, XRef *xref);
100 101 102 103
};

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

104
#define cairoFontCacheSize 64
Kristian Høgsberg's avatar
Kristian Høgsberg committed
105 106 107 108 109 110 111 112 113 114 115

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

class CairoFontEngine {
public:

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

119
  CairoFont *getFont(GfxFont *gfxFont, PDFDoc *doc, bool printing, XRef *xref);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
120 121 122 123

private:
  CairoFont *fontCache[cairoFontCacheSize];
  FT_Library lib;
124
  bool useCIDs;
125
  mutable std::recursive_mutex mutex;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
126 127 128
};

#endif