Commit 132647f8 authored by Kristian Høgsberg's avatar Kristian Høgsberg

2005-05-01 Kristian Høgsberg <krh@redhat.com>

        * poppler/CairoFontEngine.cc:
        * poppler/CairoFontEngine.h:
        * poppler/CairoOutputDev.cc: Back out workaround for cairo 0.4.0
        font API and port to new cairo head.
parent 595c18c0
2005-05-01 Kristian Høgsberg <krh@redhat.com>
* poppler/CairoFontEngine.cc:
* poppler/CairoFontEngine.h:
* poppler/CairoOutputDev.cc: Back out workaround for cairo 0.4.0
font API and port to new cairo head.
2005-05-01 Jeff Muizelaar <jeff@infidigm.net>
* splash/SplashFTFont.cc (SplashFTFont::getGlyphPath):
......
......@@ -181,9 +181,9 @@ AC_ARG_ENABLE(cairo-output,
enable_cairo_output=$enableval,
enable_cairo_output="try")
if test x$enable_cairo_output = xyes; then
PKG_CHECK_MODULES(CAIRO, cairo = 0.4.0 fontconfig)
PKG_CHECK_MODULES(CAIRO, cairo > 0.4.0 fontconfig)
elif test x$enable_cairo_output = xtry; then
PKG_CHECK_MODULES(CAIRO, cairo = 0.4.0 fontconfig,
PKG_CHECK_MODULES(CAIRO, cairo > 0.4.0 fontconfig,
[enable_cairo_output="yes"],
[enable_cairo_output="no"])
fi
......
......@@ -60,15 +60,14 @@ static CairoOutFontSubst cairoOutSubstFonts[16] = {
// CairoFont
//------------------------------------------------------------------------
/* For the 0.3 release of poppler we're creating a CairoFont, and
* thus, an FT_Face for each size of each font we encounter. We
* should of course be able to share FT_Face instances across all
* sizes of a font. However, to do that we need to be able to create
* a cairo_unscaled_font_t, which is not possible with the cairo-0.4.0
* API which is what we're targeting with this release. */
CairoFont::CairoFont(GfxFont *gfxFont, XRef *xref, FT_Library lib,
double m11, double m12, double m21, double m22) {
void cairo_font_face_destroy (void *data)
{
CairoFont *font = (CairoFont *) data;
delete font;
}
CairoFont::CairoFont(GfxFont *gfxFont, XRef *xref, FT_Library lib) {
Ref embRef;
Object refObj, strObj;
GooString *tmpFileName, *fileName, *substName,*tmpFileName2;
......@@ -80,12 +79,12 @@ CairoFont::CairoFont(GfxFont *gfxFont, XRef *xref, FT_Library lib,
char *name;
FoFiTrueType *ff;
FoFiType1C *ff1c;
cairo_matrix_t *matrix;
static cairo_user_data_key_t cairo_font_face_key;
codeToGID = NULL;
codeToGIDLen = 0;
substIdx = -1;
cairo_font = NULL;
cairo_font_face = NULL;
ref = *gfxFont->getID();
fontType = gfxFont->getType();
......@@ -245,21 +244,20 @@ CairoFont::CairoFont(GfxFont *gfxFont, XRef *xref, FT_Library lib,
unlink (fileName->getCString());
}
this->m11 = m11;
this->m12 = m12;
this->m21 = m21;
this->m22 = m22;
matrix = cairo_matrix_create ();
cairo_matrix_set_affine (matrix, m11, m12, m21, m22, 0, 0);
cairo_font = cairo_ft_font_create_for_ft_face (face, FT_LOAD_NO_HINTING,
matrix);
cairo_matrix_destroy (matrix);
if (cairo_font == NULL) {
cairo_font_face = cairo_ft_font_face_create_for_ft_face (face,
FT_LOAD_NO_HINTING |
FT_LOAD_NO_BITMAP);
if (cairo_font_face == NULL) {
error(-1, "could not create cairo font\n");
goto err2; /* this doesn't do anything, but it looks like we're
* handling the error */
}
cairo_font_face_set_user_data (cairo_font_face,
&cairo_font_face_key,
this,
cairo_font_face_destroy);
return;
err2:
/* hmm? */
......@@ -267,27 +265,17 @@ CairoFont::CairoFont(GfxFont *gfxFont, XRef *xref, FT_Library lib,
}
CairoFont::~CairoFont() {
cairo_font_destroy (cairo_font);
/* cairo_font_t's created from an FT_Face are never cached so we can
* free the font here. There might be glyphs in the cairo glyph
* cache referencing this font, but since we're throwing this font
* away, they won't be used and will slowly fall out of the
* cache. */
FT_Done_Face (face);
}
GBool
CairoFont::matches(Ref &other,
double m11, double m12, double m21, double m22) {
return (other.num == ref.num && other.gen == ref.gen &&
this->m11 == m11 && this->m12 == m12 &&
this->m21 == m21 && this->m22 == m22);
CairoFont::matches(Ref &other) {
return (other.num == ref.num && other.gen == ref.gen);
}
cairo_font_t *
CairoFont::getFont(void) {
return cairo_font;
cairo_font_face_t *
CairoFont::getFontFace(void) {
return cairo_font_face;
}
unsigned long
......@@ -359,8 +347,7 @@ CairoFontEngine::~CairoFontEngine() {
}
CairoFont *
CairoFontEngine::getFont(GfxFont *gfxFont, XRef *xref,
double m11, double m12, double m21, double m22) {
CairoFontEngine::getFont(GfxFont *gfxFont, XRef *xref) {
int i, j;
Ref ref;
CairoFont *font;
......@@ -376,7 +363,7 @@ CairoFontEngine::getFont(GfxFont *gfxFont, XRef *xref,
for (i = 0; i < cairoFontCacheSize; ++i) {
font = fontCache[i];
if (font && font->matches(ref, m11, m12, m21, m22)) {
if (font && font->matches(ref)) {
for (j = i; j > 0; --j) {
fontCache[j] = fontCache[j-1];
}
......@@ -385,7 +372,7 @@ CairoFontEngine::getFont(GfxFont *gfxFont, XRef *xref,
}
}
font = new CairoFont (gfxFont, xref, lib, m11, m12, m21, m22);
font = new CairoFont (gfxFont, xref, lib);
if (fontCache[cairoFontCacheSize - 1]) {
delete fontCache[cairoFontCacheSize - 1];
}
......
......@@ -18,18 +18,17 @@
class CairoFont {
public:
CairoFont(GfxFont *gfxFont, XRef *xref, FT_Library lib,
double m11, double m12, double m21, double m22);
CairoFont(GfxFont *gfxFont, XRef *xref, FT_Library lib);
~CairoFont();
GBool matches(Ref &other, double m11, double m12, double m21, double m22);
cairo_font_t *getFont(void);
GBool matches(Ref &other);
cairo_font_face_t *getFontFace(void);
unsigned long getGlyph(CharCode code, Unicode *u, int uLen);
double getSubstitutionCorrection(GfxFont *gfxFont);
private:
int substIdx;
Ref ref;
cairo_font_t *cairo_font;
cairo_font_face_t *cairo_font_face;
FT_Face face;
Gushort *codeToGID;
......@@ -52,8 +51,7 @@ public:
CairoFontEngine(FT_Library libA);
~CairoFontEngine();
CairoFont *getFont(GfxFont *gfxFont, XRef *xref,
double m11, double m12, double m21, double m22);
CairoFont *getFont(GfxFont *gfxFont, XRef *xref);
private:
CairoFont *fontCache[cairoFontCacheSize];
......
......@@ -76,7 +76,7 @@ void CairoOutputDev::startPage(int pageNum, GfxState *state) {
cairo_destroy (cairo);
createCairo (state);
cairo_init_clip (cairo);
cairo_reset_clip (cairo);
cairo_set_rgb_color (cairo, 0, 0, 0);
cairo_set_operator (cairo, CAIRO_OPERATOR_OVER);
cairo_set_line_cap (cairo, CAIRO_LINE_CAP_BUTT);
......@@ -197,29 +197,38 @@ void CairoOutputDev::updateStrokeColor(GfxState *state) {
}
void CairoOutputDev::updateFont(GfxState *state) {
cairo_font_t *font;
cairo_font_face_t *font_face;
double m11, m12, m21, m22;
double w;
cairo_matrix_t matrix;
LOG(printf ("updateFont() font=%s\n", state->getFont()->getName()->getCString()));
/* Needs to be rethough, since fonts are now handled by cairo */
needFontUpdate = gFalse;
currentFont = fontEngine->getFont (state->getFont(), xref);
state->getFontTransMat(&m11, &m12, &m21, &m22);
m11 *= state->getHorizScaling();
m12 *= state->getHorizScaling();
/* w = currentFont->getSubstitutionCorrection(state->getFont()); */
m12 *= -1;
m22 *= -1;
w = currentFont->getSubstitutionCorrection(state->getFont());
m12 *= -w;
m22 *= -w;
LOG(printf ("font matrix: %f %f %f %f\n", m11, m12, m21, m22));
currentFont = fontEngine->getFont (state->getFont(), xref,
m11, m21, m12, m22);
font = currentFont->getFont();
cairo_set_font (cairo, font);
font_face = currentFont->getFontFace();
cairo_set_font_face (cairo, font_face);
matrix.xx = m11;
matrix.yx = m12;
matrix.xy = m21;
matrix.yy = m22;
matrix.x0 = 0;
matrix.y0 = 0;
cairo_set_font_matrix (cairo, &matrix);
}
void CairoOutputDev::doPath(GfxState *state, GfxPath *path,
......@@ -451,8 +460,8 @@ void CairoOutputDev::endTextObject(GfxState *state) {
void CairoOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
int width, int height, GBool invert,
GBool inlineImg) {
char *buffer;
char *dest;
unsigned char *buffer;
unsigned char *dest;
cairo_surface_t *image;
int x, y;
ImageStream *imgStr;
......@@ -461,7 +470,7 @@ void CairoOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
cairo_matrix_t *mat;
int invert_bit;
buffer = (char *)malloc (width * height * 4);
buffer = (unsigned char *)malloc (width * height * 4);
if (buffer == NULL) {
error(-1, "Unable to allocate memory for image.");
return;
......@@ -523,8 +532,8 @@ void CairoOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
int width, int height,
GfxImageColorMap *colorMap,
int *maskColors, GBool inlineImg) {
char *buffer;
char *dest;
unsigned char *buffer;
unsigned char *dest;
cairo_surface_t *image;
int x, y;
ImageStream *imgStr;
......@@ -535,7 +544,7 @@ void CairoOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
cairo_matrix_t *mat;
int is_identity_transform;
buffer = (char *)malloc (width * height * 4);
buffer = (unsigned char *)malloc (width * height * 4);
if (buffer == NULL) {
error(-1, "Unable to allocate memory for image.");
......
......@@ -56,7 +56,7 @@ CairoOutputDevImage::createCairo(GfxState *state) {
memset (pixels, 0xff, pixels_w * pixels_h * 4);
cairo = cairo_create ();
cairo_set_target_image (cairo, (char *)pixels, CAIRO_FORMAT_ARGB32,
cairo_set_target_image (cairo, (unsigned char *)pixels, CAIRO_FORMAT_ARGB32,
pixels_w, pixels_h,
pixels_w*4);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment