Commit ea58a20b authored by Brad Hards's avatar Brad Hards

Initial import of Qt4 bindings, and for a Qt4 "Arthur" (QPainter)

backend renderer.

The bindings are currently unstable - you can expect substantial change
in both source and binary interfaces.

The Arthur renderer currently does a reasonable job of rendering path
and fill, but the image rendering doesn't work (for reasons that aren't
clear to me) and text rendering doesn't use the right glyphs - it just
draws with the current font. There is a lot of work to do on this
too. Help is, of coure, welcome.
parent 61e9bc76
2005-06-28 Brad Hards <bradh@frogmouth.net>
* qt4/:
* Makefile.am:
* configure.ac:
* poppler-qt4.pc.in: Initial import of Qt4 bindings, based
on the Qt3 bindings. API is still in flux.
* poppler/AuthurOutputDev.[cc,h]:
* poppler/Makefile.am: Initial import of Qt4 backend renderer.
Incomplete at this stage.
2005-06-27 Kristian Høgsberg <krh@redhat.com>
* poppler/CairoOutputDev.cc:
......
......@@ -17,7 +17,12 @@ qt_subdir = qt
qt_pc_file = poppler-qt.pc
endif
SUBDIRS = goo fofi $(splash_subdir) poppler $(glib_subdir) $(qt_subdir) test
if BUILD_POPPLER_QT4
qt4_subdir = qt4
qt4_pc_file = poppler-qt4.pc
endif
SUBDIRS = goo fofi $(splash_subdir) poppler $(glib_subdir) $(qt_subdir) test $(qt4_subdir)
EXTRA_DIST = \
README-XPDF \
......@@ -32,4 +37,5 @@ pkgconfig_DATA = \
$(cairo_pc_file) \
$(splash_pc_file) \
$(glib_pc_file) \
$(qt_pc_file)
$(qt_pc_file) \
$(qt4_pc_file)
......@@ -295,6 +295,93 @@ elif test x$enable_poppler_qt = xtry; then
fi
AM_CONDITIONAL(BUILD_POPPLER_QT, test x$enable_poppler_qt = xyes)
dnl
dnl Try Qt4
dnl
AC_ARG_ENABLE(poppler-qt4,
AC_HELP_STRING([--disable-poppler-qt4],
[Don't compile poppler Qt4 wrapper.]),
enable_poppler_qt4=$enableval,
enable_poppler_qt4="try")
have_qt4=no
dnl ===================================================================
dnl Check whether the Qt4 libraries are available.
dnl Adapted from Qt3 check above!
dnl ===================================================================
dnl Search paths for Qt4 - not much real experience with this yet.
qt4_incdirs="/usr/local/qt/include /usr/include/qt /usr/include /usr/X11R6/include/X11/qt /usr/X11R6/include/qt /usr/lib/qt/include"
qt4_libdirs="/usr/local/qt/lib /usr/lib/qt /usr/lib /usr/X11R6/lib/X11/qt /usr/X11R6/lib/qt /usr/lib/qt/lib"
if test -n "$QTDIR" ; then
qt4_incdirs="$QTDIR/include $qt4_incdirs"
qt4_libdirs="$QTDIR/lib $qt4_libdirs"
fi
dnl What to test
qt4_test_include="QtCore/QCoreApplication"
qt4_test_la_library="libQtCore.la"
qt4_test_library="libQtCore.so"
dnl Check for Qt4 headers
AC_MSG_CHECKING([for Qt4 headers])
qt4_incdir="no"
for it in $qt4_incdirs ; do
if test -r "$it/$qt4_test_include" ; then
qt4_incdir="$it"
break
fi
done
AC_MSG_RESULT([$qt4_incdir])
dnl Check for Qt4 libraries
AC_MSG_CHECKING([for Qt4 libraries])
qt4_libdir="no"
for qt4_check in $qt4_libdirs ; do
if test -r "$qt4_check/$qt4_test_la_library" ; then
qt4_libdir="$qt4_check"
break
fi
if test -r "$qt4_check/$qt4_test_library" ; then
qt4_libdir="$qt4_check"
break
fi
done
AC_MSG_RESULT([$qt4_libdir])
if test "x$qt4_libdir" != "xno" ; then
if test "x$qt4_incdir" != "xno" ; then
have_qt4=yes;
fi
fi
dnl Set the variables
POPPLER_QT4_CXXFLAGS="-I$qt4_incdir"
POPPLER_QT4_LIBS="-L$qt4_libdir -lQtCore -lQtGui"
AC_SUBST(POPPLER_QT4_CXXFLAGS)
AC_SUBST(POPPLER_QT4_LIBS)
if test x$have_qt4 = xno ; then
AC_MSG_WARN([Qt4 development libraries not found])
fi
if test x$enable_poppler_qt4 = xyes; then
if test x$have_qt4 = xno; then
AC_MSG_ERROR([Qt4 integration explicitly required, and Qt4 libraries not found])
fi
elif test x$enable_poppler_qt4 = xtry; then
if test x$have_qt4 = xyes; then
enable_poppler_qt4="yes"
else
enable_poppler_qt4="no"
fi
fi
AM_CONDITIONAL(BUILD_POPPLER_QT4, test x$enable_poppler_qt4 = xyes)
AC_ARG_ENABLE(gtk-test,
AC_HELP_STRING([--disable-gtk-test],
[Don't compile GTK+ test program.]),
......@@ -339,11 +426,15 @@ poppler/Makefile
glib/Makefile
test/Makefile
qt/Makefile
qt4/Makefile
qt4/src/Makefile
qt4/tests/Makefile
poppler.pc
poppler-cairo.pc
poppler-splash.pc
poppler-glib.pc
poppler-qt.pc])
poppler-qt.pc
poppler-qt4.pc])
echo ""
......@@ -351,6 +442,7 @@ echo "Building poppler with support for:"
echo " splash output: $enable_splash_output"
echo " cairo output: $enable_cairo_output"
echo " qt wrapper: $enable_poppler_qt"
echo " qt4 wrapper: $enable_poppler_qt4"
echo " glib wrapper: $enable_poppler_glib"
echo " use libjpeg: $enable_libjpeg"
echo " use zlib: $enable_zlib"
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
Name: poppler-qt4
Description: Qt4 bindings for poppler
Version: @VERSION@
Requires: poppler = @VERSION@
Libs: -L${libdir} -lpoppler-qt4
Cflags: -I${includedir}/poppler
//========================================================================
//
// ArthurOutputDev.cc
//
// Copyright 2003 Glyph & Cog, LLC
// Copyright 2004 Red Hat, Inc
//
//========================================================================
#include <config.h>
#ifdef USE_GCC_PRAGMAS
#pragma implementation
#endif
#include <string.h>
#include <math.h>
#include "goo/gfile.h"
#include "GlobalParams.h"
#include "Error.h"
#include "Object.h"
#include "GfxState.h"
#include "GfxFont.h"
#include "Link.h"
#include "CharCodeToUnicode.h"
#include "FontEncodingTables.h"
#include <fofi/FoFiTrueType.h>
#include "ArthurOutputDev.h"
#include <QtCore/QtDebug>
#include <QtGui/QPainterPath>
//------------------------------------------------------------------------
//------------------------------------------------------------------------
// ArthurOutputDev
//------------------------------------------------------------------------
ArthurOutputDev::ArthurOutputDev(QPainter *painter):
m_painter(painter)
{
m_currentBrush = QBrush(Qt::SolidPattern);
}
ArthurOutputDev::~ArthurOutputDev()
{
}
void ArthurOutputDev::startDoc(XRef *xrefA) {
}
void ArthurOutputDev::startPage(int pageNum, GfxState *state)
{
}
void ArthurOutputDev::endPage() {
}
void ArthurOutputDev::drawLink(Link *link, Catalog *catalog)
{
}
void ArthurOutputDev::saveState(GfxState *state)
{
m_painter->save();
}
void ArthurOutputDev::restoreState(GfxState *state)
{
m_painter->restore();
}
void ArthurOutputDev::updateAll(GfxState *state)
{
qDebug() << "updateAll";
}
void ArthurOutputDev::updateCTM(GfxState *state, double m11, double m12,
double m21, double m22,
double m31, double m32)
{
qDebug() << "updateCTM";
}
void ArthurOutputDev::updateLineDash(GfxState *state)
{
qDebug() << "updateLineDash";
}
void ArthurOutputDev::updateFlatness(GfxState *state)
{
qDebug() << "updateFlatness";
}
void ArthurOutputDev::updateLineJoin(GfxState *state)
{
switch (state->getLineJoin()) {
case 0:
m_currentPen.setJoinStyle(Qt::MiterJoin);
break;
case 1:
m_currentPen.setJoinStyle(Qt::RoundJoin);
break;
case 2:
m_currentPen.setJoinStyle(Qt::BevelJoin);
break;
}
m_painter->setPen(m_currentPen);
}
void ArthurOutputDev::updateLineCap(GfxState *state)
{
switch (state->getLineCap()) {
case 0:
m_currentPen.setCapStyle(Qt::FlatCap);
break;
case 1:
m_currentPen.setCapStyle(Qt::RoundCap);
break;
case 2:
m_currentPen.setCapStyle(Qt::SquareCap);
break;
}
m_painter->setPen(m_currentPen);
}
void ArthurOutputDev::updateMiterLimit(GfxState *state)
{
#if 0
cairo_set_miter_limit (cairo, state->getMiterLimit());
#endif
}
void ArthurOutputDev::updateLineWidth(GfxState *state)
{
m_currentPen.setWidthF(state->getTransformedLineWidth());
m_painter->setPen(m_currentPen);
}
void ArthurOutputDev::updateFillColor(GfxState *state)
{
GfxRGB rgb;
QColor brushColour = m_currentBrush.color();
state->getFillRGB(&rgb);
brushColour.setRgbF(rgb.r, rgb.g, rgb.b, brushColour.alphaF());
m_currentBrush.setColor(brushColour);
m_painter->setBrush(m_currentBrush);
}
void ArthurOutputDev::updateStrokeColor(GfxState *state)
{
GfxRGB rgb;
QColor penColour = m_currentPen.color();
state->getStrokeRGB(&rgb);
penColour.setRgbF(rgb.r, rgb.g, rgb.b, penColour.alphaF());
m_currentPen.setColor(penColour);
m_painter->setPen(m_currentPen);
}
void ArthurOutputDev::updateFillOpacity(GfxState *state)
{
QColor brushColour= m_currentBrush.color();
brushColour.setAlphaF(state->getFillOpacity());
m_currentBrush.setColor(brushColour);
m_painter->setBrush(m_currentBrush);
}
void ArthurOutputDev::updateStrokeOpacity(GfxState *state)
{
QColor penColour= m_currentPen.color();
penColour.setAlphaF(state->getStrokeOpacity());
m_currentPen.setColor(penColour);
m_painter->setPen(m_currentPen);
}
void ArthurOutputDev::updateFont(GfxState *state)
{
// Something like
// currentFont.setPointSize( state->getFontSize() );
// m_painter->setFont(currentFont);
// but with transformation matrices and such...
#if 0
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 *= w;
m22 *= w;
LOG(printf ("font matrix: %f %f %f %f\n", m11, m12, m21, m22));
font_face = currentFont->getFontFace();
cairo_set_font_face (cairo, font_face);
matrix.xx = m11;
matrix.xy = -m21;
matrix.yx = m12;
matrix.yy = -m22;
matrix.x0 = 0;
matrix.y0 = 0;
cairo_set_font_matrix (cairo, &matrix);
#endif
}
static QPainterPath convertPath(GfxState *state, GfxPath *path)
{
GfxSubpath *subpath;
double x1, y1, x2, y2, x3, y3;
int i, j;
QPainterPath qPath;
for (i = 0; i < path->getNumSubpaths(); ++i) {
subpath = path->getSubpath(i);
if (subpath->getNumPoints() > 0) {
state->transform(subpath->getX(0), subpath->getY(0), &x1, &y1);
qPath.moveTo(x1, y1);
j = 1;
while (j < subpath->getNumPoints()) {
if (subpath->getCurve(j)) {
state->transform(subpath->getX(j), subpath->getY(j), &x1, &y1);
state->transform(subpath->getX(j+1), subpath->getY(j+1), &x2, &y2);
state->transform(subpath->getX(j+2), subpath->getY(j+2), &x3, &y3);
qPath.cubicTo( x1, y1, x2, y2, x3, y3);
j += 3;
} else {
state->transform(subpath->getX(j), subpath->getY(j), &x1, &y1);
qPath.lineTo(x1, y1);
++j;
}
}
if (subpath->isClosed()) {
qPath.closeSubpath();
}
}
}
return qPath;
}
void ArthurOutputDev::stroke(GfxState *state)
{
m_painter->drawPath( convertPath( state, state->getPath() ) );
}
void ArthurOutputDev::fill(GfxState *state)
{
m_painter->fillPath( convertPath( state, state->getPath() ), m_currentBrush );
}
void ArthurOutputDev::eoFill(GfxState *state)
{
#if 0
doPath (state, state->getPath(), gFalse);
cairo_set_fill_rule (cairo, CAIRO_FILL_RULE_EVEN_ODD);
cairo_set_source_rgb (cairo,
fill_color.r, fill_color.g, fill_color.b);
LOG(printf ("fill-eo\n"));
cairo_fill (cairo);
#endif
}
void ArthurOutputDev::clip(GfxState *state)
{
qDebug() << "got clip";
m_painter->setClipPath(convertPath( state, state->getPath() ) );
}
void ArthurOutputDev::eoClip(GfxState *state)
{
qDebug() << "got eoClip";
#if 0
doPath (state, state->getPath(), gFalse);
cairo_set_fill_rule (cairo, CAIRO_FILL_RULE_EVEN_ODD);
cairo_clip (cairo);
LOG (printf ("clip-eo\n"));
#endif
}
void ArthurOutputDev::drawString(GfxState *state, GooString *s)
{
GfxFont *font;
int wMode;
int render;
// the number of bytes in the string and not the number of glyphs?
int len = s->getLength();
char *p = s->getCString();
int count = 0;
double curX, curY;
double riseX, riseY;
font = state->getFont();
wMode = font->getWMode();
if (m_needFontUpdate) {
updateFont(state);
}
// check for invisible text -- this is used by Acrobat Capture
render = state->getRender();
if (render == 3) {
return;
}
// ignore empty strings
if (len == 0)
return;
state->textTransformDelta(0, state->getRise(), &riseX, &riseY);
curX = state->getCurX();
curY = state->getCurY();
while (len > 0) {
double x, y;
double x1, y1;
double dx, dy, tdx, tdy;
double originX, originY, tOriginX, tOriginY;
int n, uLen;
CharCode code;
Unicode u[8];
n = font->getNextChar(p, len, &code,
u, (int)(sizeof(u) / sizeof(Unicode)), &uLen,
&dx, &dy, &originX, &originY);
if (wMode) {
dx *= state->getFontSize();
dy = dy * state->getFontSize() + state->getCharSpace();
if (n == 1 && *p == ' ') {
dy += state->getWordSpace();
}
} else {
dx = dx * state->getFontSize() + state->getCharSpace();
if (n == 1 && *p == ' ') {
dx += state->getWordSpace();
}
dx *= state->getHorizScaling();
dy *= state->getFontSize();
}
originX *= state->getFontSize();
originY *= state->getFontSize();
state->textTransformDelta(dx, dy, &tdx, &tdy);
state->textTransformDelta(originX, originY, &tOriginX, &tOriginY);
x = curX + riseX;
y = curY + riseY;
x -= tOriginX;
y -= tOriginY;
state->transform(x, y, &x1, &y1);
//glyphs[count].index = currentFont->getGlyph (code, u, uLen);
m_painter->drawText(QPointF(x1,y1), QString(*p) );
curX += tdx;
curY += tdy;
p += n;
len -= n;
count++;
}
#if 0
// fill
if (!(render & 1)) {
LOG (printf ("fill string\n"));
cairo_set_source_rgb (cairo,
fill_color.r, fill_color.g, fill_color.b);
cairo_show_glyphs (cairo, glyphs, count);
}
// stroke
if ((render & 3) == 1 || (render & 3) == 2) {
LOG (printf ("stroke string\n"));
cairo_set_source_rgb (cairo,
stroke_color.r, stroke_color.g, stroke_color.b);
cairo_glyph_path (cairo, glyphs, count);
cairo_stroke (cairo);
}
// clip
if (render & 4) {
// FIXME: This is quite right yet, we need to accumulate all
// glyphs within one text object before we clip. Right now this
// just add this one string.
LOG (printf ("clip string\n"));
cairo_glyph_path (cairo, glyphs, count);
cairo_clip (cairo);
}
#endif
}
GBool ArthurOutputDev::beginType3Char(GfxState *state, double x, double y,
double dx, double dy,
CharCode code, Unicode *u, int uLen)
{
return gFalse;
}
void ArthurOutputDev::endType3Char(GfxState *state)
{
}
void ArthurOutputDev::type3D0(GfxState *state, double wx, double wy)
{
}
void ArthurOutputDev::type3D1(GfxState *state, double wx, double wy,
double llx, double lly, double urx, double ury)
{
}
void ArthurOutputDev::endTextObject(GfxState *state)
{
}
void ArthurOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
int width, int height, GBool invert,
GBool inlineImg)
{
qDebug() << "drawImageMask";
#if 0
unsigned char *buffer;
unsigned char *dest;
cairo_surface_t *image;
cairo_pattern_t *pattern;
int x, y;
ImageStream *imgStr;
Guchar *pix;
double *ctm;
cairo_matrix_t matrix;
int invert_bit;
int row_stride;
row_stride = (width + 3) & ~3;
buffer = (unsigned char *) malloc (height * row_stride);
if (buffer == NULL) {
error(-1, "Unable to allocate memory for image.");
return;
}
/* TODO: Do we want to cache these? */
imgStr = new ImageStream(str, width, 1, 1);
imgStr->reset();
invert_bit = invert ? 1 : 0;
for (y = 0; y < height; y++) {
pix = imgStr->getLine();
dest = buffer + y * row_stride;
for (x = 0; x < width; x++) {
if (pix[x] ^ invert_bit)
*dest++ = 0;
else
*dest++ = 255;
}
}
image = cairo_image_surface_create_for_data (buffer, CAIRO_FORMAT_A8,
width, height, row_stride);
if (image == NULL)
return;
pattern = cairo_pattern_create_for_surface (image);
if (pattern == NULL)
return;
ctm = state->getCTM();
LOG (printf ("drawImageMask %dx%d, matrix: %f, %f, %f, %f, %f, %f\n",
width, height, ctm[0], ctm[1], ctm[2], ctm[3], ctm[4], ctm[5]));
matrix.xx = ctm[0] / width;
matrix.xy = -ctm[2] / height;
matrix.yx = ctm[1] / width;
matrix.yy = -ctm[3] / height;
matrix.x0 = ctm[2] + ctm[4];
matrix.y0 = ctm[3] + ctm[5];
cairo_matrix_invert (&matrix);
cairo_pattern_set_matrix (pattern, &matrix);
cairo_pattern_set_filter (pattern, CAIRO_FILTER_BEST);
/* FIXME: Doesn't the image mask support any colorspace? */
cairo_set_source_rgb (cairo, fill_color.r, fill_color.g, fill_color.b);
cairo_mask (cairo, pattern);
cairo_pattern_destroy (pattern);
cairo_surface_destroy (image);
free (buffer);
delete imgStr;
#endif
}
//TODO: lots more work here.
void ArthurOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
int width, int height,
GfxImageColorMap *colorMap,
int *maskColors, GBool inlineImg)
{
qDebug() << "drawImage";
if (inlineImg == gTrue) {
qDebug() << "drawImage inline";
}
unsigned char *buffer;
unsigned int *dest;
// cairo_surface_t *image;
// cairo_pattern_t *pattern;
int x, y;
ImageStream *imgStr;
Guchar *pix;
GfxRGB rgb;
int alpha, i;
double *ctm;
// cairo_matrix_t matrix;
QMatrix matrix;
int is_identity_transform;
buffer = (unsigned char *)gmalloc (width * height * 4);
/* TODO: Do we want to cache these? */
imgStr = new ImageStream(str, width,
colorMap->getNumPixelComps(),
colorMap->getBits());
imgStr->reset();
/* ICCBased color space doesn't do any color correction
* so check its underlying color space as well */
is_identity_transform = colorMap->getColorSpace()->getMode() == csDeviceRGB ||