Commit b29582cd authored by Matthias Fauconneau's avatar Matthias Fauconneau Committed by Pino Toscano
Browse files

[arthur] small fixes and memory leaks

- fix font rendering (transforming the glyph path and not only the glyph origin)
- fix image rendering (alpha was set to zero)
parent 970f0755
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
// Copyright (C) 2008, 2010 Pino Toscano <pino@kde.org> // Copyright (C) 2008, 2010 Pino Toscano <pino@kde.org>
// Copyright (C) 2009 Carlos Garcia Campos <carlosgc@gnome.org> // Copyright (C) 2009 Carlos Garcia Campos <carlosgc@gnome.org>
// Copyright (C) 2009 Petr Gajdos <pgajdos@novell.com> // Copyright (C) 2009 Petr Gajdos <pgajdos@novell.com>
// Copyright (C) 2010 Matthias Fauconneau <matthias.fauconneau@gmail.com>
// //
// To see a description of the changes please see the Changelog file that // 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 // came with your tarball or type make ChangeLog if you are building from git
...@@ -269,7 +270,7 @@ void ArthurOutputDev::updateFont(GfxState *state) ...@@ -269,7 +270,7 @@ void ArthurOutputDev::updateFont(GfxState *state)
GfxFontType fontType; GfxFontType fontType;
SplashOutFontFileID *id; SplashOutFontFileID *id;
SplashFontFile *fontFile; SplashFontFile *fontFile;
SplashFontSrc *fontsrc; SplashFontSrc *fontsrc = NULL;
FoFiTrueType *ff; FoFiTrueType *ff;
Ref embRef; Ref embRef;
Object refObj, strObj; Object refObj, strObj;
...@@ -342,7 +343,7 @@ void ArthurOutputDev::updateFont(GfxState *state) ...@@ -342,7 +343,7 @@ void ArthurOutputDev::updateFont(GfxState *state)
if (fileName) if (fileName)
fontsrc->setFile(fileName, gFalse); fontsrc->setFile(fileName, gFalse);
else else
fontsrc->setBuf(tmpBuf, tmpBufLen, gFalse); fontsrc->setBuf(tmpBuf, tmpBufLen, gTrue);
// load the font file // load the font file
switch (fontType) { switch (fontType) {
...@@ -484,11 +485,15 @@ void ArthurOutputDev::updateFont(GfxState *state) ...@@ -484,11 +485,15 @@ void ArthurOutputDev::updateFont(GfxState *state)
mat[2] = m21; mat[3] = -m22; mat[2] = m21; mat[3] = -m22;
m_font = m_fontEngine->getFont(fontFile, mat, matrix); m_font = m_fontEngine->getFont(fontFile, mat, matrix);
if (fontsrc && !fontsrc->isFile)
fontsrc->unref();
return; return;
err2: err2:
delete id; delete id;
err1: err1:
if (fontsrc && !fontsrc->isFile)
fontsrc->unref();
return; return;
#endif #endif
} }
...@@ -530,7 +535,7 @@ static QPainterPath convertPath(GfxState *state, GfxPath *path, Qt::FillRule fil ...@@ -530,7 +535,7 @@ static QPainterPath convertPath(GfxState *state, GfxPath *path, Qt::FillRule fil
void ArthurOutputDev::stroke(GfxState *state) void ArthurOutputDev::stroke(GfxState *state)
{ {
m_painter->drawPath( convertPath( state, state->getPath(), Qt::OddEvenFill ) ); m_painter->strokePath( convertPath( state, state->getPath(), Qt::OddEvenFill ), m_currentPen );
} }
void ArthurOutputDev::fill(GfxState *state) void ArthurOutputDev::fill(GfxState *state)
...@@ -559,6 +564,7 @@ void ArthurOutputDev::drawChar(GfxState *state, double x, double y, ...@@ -559,6 +564,7 @@ void ArthurOutputDev::drawChar(GfxState *state, double x, double y,
CharCode code, int nBytes, Unicode *u, int uLen) { CharCode code, int nBytes, Unicode *u, int uLen) {
#ifdef HAVE_SPLASH #ifdef HAVE_SPLASH
double x1, y1; double x1, y1;
double x2, y2;
// SplashPath *path; // SplashPath *path;
int render; int render;
...@@ -577,41 +583,36 @@ void ArthurOutputDev::drawChar(GfxState *state, double x, double y, ...@@ -577,41 +583,36 @@ void ArthurOutputDev::drawChar(GfxState *state, double x, double y,
x -= originX; x -= originX;
y -= originY; y -= originY;
state->transform(x, y, &x1, &y1);
// fill // fill
if (!(render & 1)) { if (!(render & 1)) {
int x0, y0, xFrac, yFrac;
x0 = static_cast<int>(floor(x1));
xFrac = splashFloor((x1 - x0) * splashFontFraction);
y0 = static_cast<int>(floor(y1));
yFrac = splashFloor((y1 - y0) * splashFontFraction);
SplashPath * fontPath; SplashPath * fontPath;
fontPath = m_font->getGlyphPath(code); fontPath = m_font->getGlyphPath(code);
if (fontPath) { if (fontPath) {
QPainterPath qPath; QPainterPath qPath;
qPath.setFillRule(Qt::WindingFill); qPath.setFillRule(Qt::WindingFill);
for (int i = 0; i < fontPath->length; ++i) { for (int i = 0; i < fontPath->length; ++i) {
if (fontPath->flags[i] & splashPathFirst) { if (fontPath->flags[i] & splashPathFirst) {
qPath.moveTo(fontPath->pts[i].x+x0, fontPath->pts[i].y+y0); state->transform(fontPath->pts[i].x+x, -fontPath->pts[i].y+y, &x1, &y1);
} else if (fontPath->flags[i] & splashPathCurve) { qPath.moveTo(x1,y1);
qPath.quadTo(fontPath->pts[i].x+x0, fontPath->pts[i].y+y0, } else if (fontPath->flags[i] & splashPathCurve) {
fontPath->pts[i+1].x+x0, fontPath->pts[i+1].y+y0); state->transform(fontPath->pts[i].x+x, -fontPath->pts[i].y+y, &x1, &y1);
++i; state->transform(fontPath->pts[i+1].x+x, -fontPath->pts[i+1].y+y, &x2, &y2);
} qPath.quadTo(x1,y1,x2,y2);
// FIXME fix this ++i;
// else if (fontPath->flags[i] & splashPathArcCW) { }
// qDebug() << "Need to implement arc"; // FIXME fix this
// } // else if (fontPath->flags[i] & splashPathArcCW) {
else { // qDebug() << "Need to implement arc";
qPath.lineTo(fontPath->pts[i].x+x0, fontPath->pts[i].y+y0); // }
} else {
if (fontPath->flags[i] & splashPathLast) { state->transform(fontPath->pts[i].x+x, -fontPath->pts[i].y+y, &x1, &y1);
qPath.closeSubpath(); qPath.lineTo(x1,y1);
} }
if (fontPath->flags[i] & splashPathLast) {
qPath.closeSubpath();
}
} }
m_painter->save();
GfxRGB rgb; GfxRGB rgb;
QColor brushColour = m_currentBrush.color(); QColor brushColour = m_currentBrush.color();
state->getFillRGB(&rgb); state->getFillRGB(&rgb);
...@@ -622,7 +623,7 @@ void ArthurOutputDev::drawChar(GfxState *state, double x, double y, ...@@ -622,7 +623,7 @@ void ArthurOutputDev::drawChar(GfxState *state, double x, double y,
penColour.setRgbF(colToDbl(rgb.r), colToDbl(rgb.g), colToDbl(rgb.b), state->getStrokeOpacity()); penColour.setRgbF(colToDbl(rgb.r), colToDbl(rgb.g), colToDbl(rgb.b), state->getStrokeOpacity());
m_painter->setPen(penColour); m_painter->setPen(penColour);
m_painter->drawPath( qPath ); m_painter->drawPath( qPath );
m_painter->restore(); delete fontPath;
} }
} }
...@@ -762,8 +763,8 @@ void ArthurOutputDev::drawImage(GfxState *state, Object *ref, Stream *str, ...@@ -762,8 +763,8 @@ void ArthurOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
GfxImageColorMap *colorMap, GfxImageColorMap *colorMap,
GBool interpolate, int *maskColors, GBool inlineImg) GBool interpolate, int *maskColors, GBool inlineImg)
{ {
unsigned char *buffer; unsigned int *data;
unsigned int *dest; unsigned int *line;
int x, y; int x, y;
ImageStream *imgStr; ImageStream *imgStr;
Guchar *pix; Guchar *pix;
...@@ -771,9 +772,9 @@ void ArthurOutputDev::drawImage(GfxState *state, Object *ref, Stream *str, ...@@ -771,9 +772,9 @@ void ArthurOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
double *ctm; double *ctm;
QMatrix matrix; QMatrix matrix;
int is_identity_transform; int is_identity_transform;
QImage image;
int stride;
buffer = (unsigned char *)gmallocn3(width, height, 4);
/* TODO: Do we want to cache these? */ /* TODO: Do we want to cache these? */
imgStr = new ImageStream(str, width, imgStr = new ImageStream(str, width,
colorMap->getNumPixelComps(), colorMap->getNumPixelComps(),
...@@ -786,51 +787,36 @@ void ArthurOutputDev::drawImage(GfxState *state, Object *ref, Stream *str, ...@@ -786,51 +787,36 @@ void ArthurOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
(colorMap->getColorSpace()->getMode() == csICCBased && (colorMap->getColorSpace()->getMode() == csICCBased &&
((GfxICCBasedColorSpace*)colorMap->getColorSpace())->getAlt()->getMode() == csDeviceRGB); ((GfxICCBasedColorSpace*)colorMap->getColorSpace())->getAlt()->getMode() == csDeviceRGB);
if (maskColors) { image = QImage(width, height, QImage::Format_ARGB32);
for (y = 0; y < height; y++) { data = (unsigned int *)image.bits();
dest = (unsigned int *) (buffer + y * 4 * width); stride = image.bytesPerLine()/4;
pix = imgStr->getLine(); for (y = 0; y < height; y++) {
colorMap->getRGBLine (pix, dest, width); pix = imgStr->getLine();
line = data+y*stride;
colorMap->getRGBLine(pix, line, width);
if (maskColors) {
for (x = 0; x < width; x++) { for (x = 0; x < width; x++) {
for (i = 0; i < colorMap->getNumPixelComps(); ++i) { for (i = 0; i < colorMap->getNumPixelComps(); ++i) {
if (pix[i] < maskColors[2*i] * 255||
if (pix[i] < maskColors[2*i] * 255|| pix[i] > maskColors[2*i+1] * 255) {
pix[i] > maskColors[2*i+1] * 255) { *line = *line | 0xff000000;
*dest = *dest | 0xff000000; break;
break; }
} }
} pix += colorMap->getNumPixelComps();
pix += colorMap->getNumPixelComps(); line++;
dest++;
} }
} else {
for (x = 0; x < width; x++) { *line = *line | 0xff000000; line++; }
} }
m_image = new QImage(buffer, width, height, QImage::Format_ARGB32);
}
else {
for (y = 0; y < height; y++) {
dest = (unsigned int *) (buffer + y * 4 * width);
pix = imgStr->getLine();
colorMap->getRGBLine (pix, dest, width);
}
m_image = new QImage(buffer, width, height, QImage::Format_RGB32);
} }
if (m_image == NULL || m_image->isNull()) {
qDebug() << "Null image";
delete imgStr;
return;
}
ctm = state->getCTM(); ctm = state->getCTM();
matrix.setMatrix(ctm[0] / width, ctm[1] / width, -ctm[2] / height, -ctm[3] / height, ctm[2] + ctm[4], ctm[3] + ctm[5]); matrix.setMatrix(ctm[0] / width, ctm[1] / width, -ctm[2] / height, -ctm[3] / height, ctm[2] + ctm[4], ctm[3] + ctm[5]);
m_painter->setMatrix(matrix, true); m_painter->setMatrix(matrix, true);
m_painter->drawImage( QPoint(0,0), *m_image ); m_painter->drawImage( QPoint(0,0), image );
delete m_image;
m_image = 0;
free (buffer);
delete imgStr; delete imgStr;
} }
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