summaryrefslogtreecommitdiff
authorsandman <sandman>2002-04-16 22:22:14 (UTC)
committer sandman <sandman>2002-04-16 22:22:14 (UTC)
commitf27ad352830a751937dc427f2677753545f38b16 (patch) (side-by-side diff)
tree654858e6708eaaf09dd146a72f5fe1dbbf99a536
parentece373988ee95e4dc3c22eeb012a077595740057 (diff)
downloadopie-f27ad352830a751937dc427f2677753545f38b16.zip
opie-f27ad352830a751937dc427f2677753545f38b16.tar.gz
opie-f27ad352830a751937dc427f2677753545f38b16.tar.bz2
Fix (previous commit was an experimental version)
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/unsupported/qpdf/QOutputDev.cpp2
1 files changed, 0 insertions, 2 deletions
diff --git a/noncore/unsupported/qpdf/QOutputDev.cpp b/noncore/unsupported/qpdf/QOutputDev.cpp
index 15a58b1..f587a33 100644
--- a/noncore/unsupported/qpdf/QOutputDev.cpp
+++ b/noncore/unsupported/qpdf/QOutputDev.cpp
@@ -1,377 +1,375 @@
///========================================================================
//
// QOutputDev.cc
//
// Copyright 1996 Derek B. Noonburg
// CopyRight 2002 Robert Griebl
//
//========================================================================
#ifdef __GNUC__
#pragma implementation
#endif
#include <aconf.h>
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include "GString.h"
#include "Object.h"
#include "Stream.h"
#include "Link.h"
#include "GfxState.h"
#include "GfxFont.h"
#include "UnicodeMap.h"
#include "CharCodeToUnicode.h"
#include "FontFile.h"
#include "Error.h"
#include "TextOutputDev.h"
#include "QOutputDev.h"
#include <qpixmap.h>
#include <qimage.h>
#include <qpainter.h>
#include <qdict.h>
#include <qtimer.h>
#include <qapplication.h>
#include <qclipboard.h>
//#define QPDFDBG(x) x // special debug mode
#define QPDFDBG(x) // normal compilation
//------------------------------------------------------------------------
// Constants and macros
//------------------------------------------------------------------------
static inline QColor q_col ( const GfxRGB &rgb )
{
return QColor ( lrint ( rgb. r * 255 ), lrint ( rgb. g * 255 ), lrint ( rgb. b * 255 ));
}
//------------------------------------------------------------------------
// Font substitutions
//------------------------------------------------------------------------
struct QOutFontSubst {
char * m_name;
char * m_sname;
bool m_bold;
bool m_italic;
QFont::StyleHint m_hint;
};
static QOutFontSubst qStdFonts [] = {
{ "Helvetica", "Helvetica", false, false, QFont::Helvetica },
{ "Helvetica-Oblique", "Helvetica", false, true, QFont::Helvetica },
{ "Helvetica-Bold", "Helvetica", true, false, QFont::Helvetica },
{ "Helvetica-BoldOblique", "Helvetica", true, true, QFont::Helvetica },
{ "Times-Roman", "Times", false, false, QFont::Times },
{ "Times-Italic", "Times", false, true, QFont::Times },
{ "Times-Bold", "Times", true, false, QFont::Times },
{ "Times-BoldItalic", "Times", true, true, QFont::Times },
{ "Courier", "Courier", false, false, QFont::Courier },
{ "Courier-Oblique", "Courier", false, true, QFont::Courier },
{ "Courier-Bold", "Courier", true, false, QFont::Courier },
{ "Courier-BoldOblique", "Courier", true, true, QFont::Courier },
{ "Symbol", 0, false, false, QFont::AnyStyle },
{ "Zapf-Dingbats", 0, false, false, QFont::AnyStyle },
{ 0, 0, false, false, QFont::AnyStyle }
};
QFont QOutputDev::matchFont ( GfxFont *gfxFont, fp_t m11, fp_t m12, fp_t m21, fp_t m22 )
{
static QDict<QOutFontSubst> stdfonts;
// build dict for std. fonts on first invocation
if ( stdfonts. isEmpty ( )) {
for ( QOutFontSubst *ptr = qStdFonts; ptr-> m_name; ptr++ ) {
stdfonts. insert ( QString ( ptr-> m_name ), ptr );
}
}
// compute size and normalized transform matrix
int size = lrint ( sqrt ( m21 * m21 + m22 * m22 ));
QPDFDBG( printf ( "SET FONT: Name=%s, Size=%d, Bold=%d, Italic=%d, Mono=%d, Serif=%d, Symbol=%d, CID=%d, EmbFN=%s, M=(%f,%f,%f,%f)\n",
(( gfxFont-> getName ( )) ? gfxFont-> getName ( )-> getCString ( ) : "<n/a>" ),
size,
gfxFont-> isBold ( ),
gfxFont-> isItalic ( ),
gfxFont-> isFixedWidth ( ),
gfxFont-> isSerif ( ),
gfxFont-> isSymbolic ( ),
gfxFont-> isCIDFont ( ),
( gfxFont-> getEmbeddedFontName ( ) ? gfxFont-> getEmbeddedFontName ( ) : "<n/a>" ),
(double) m11, (double) m12, (double) m21, (double) m22 ));
QString fname (( gfxFont-> getName ( )) ? gfxFont-> getName ( )-> getCString ( ) : "<n/a>" );
QFont f;
f. setPixelSize ( size > 0 ? size : 8 ); // type3 fonts misbehave sometimes
// fast lookup for std. fonts
QOutFontSubst *subst = stdfonts [fname];
if ( subst ) {
if ( subst-> m_sname )
f. setFamily ( subst-> m_sname );
f. setStyleHint ( subst-> m_hint, (QFont::StyleStrategy) ( QFont::PreferOutline | QFont::PreferQuality ));
f. setBold ( subst-> m_bold );
f. setItalic ( subst-> m_italic );
}
else {
QFont::StyleHint sty;
if ( gfxFont-> isSerif ( ))
sty = QFont::Serif;
else if ( gfxFont-> isFixedWidth ( ))
sty = QFont::TypeWriter;
else
sty = QFont::Helvetica;
f. setStyleHint ( sty, (QFont::StyleStrategy) ( QFont::PreferOutline | QFont::PreferQuality ));
f. setBold ( gfxFont-> isBold ( ) > 0 );
f. setItalic ( gfxFont-> isItalic ( ) > 0 );
f. setFixedPitch ( gfxFont-> isFixedWidth ( ) > 0 );
// common specifiers in font names
if ( fname. contains ( "Oblique" ) || fname. contains ( "Italic" ))
f. setItalic ( true );
if ( fname. contains ( "Bold" ))
f. setWeight ( QFont::Bold );
if ( fname. contains ( "Demi" ))
f. setWeight ( QFont::DemiBold );
if ( fname. contains ( "Light" ))
f. setWeight ( QFont::Light );
if ( fname. contains ( "Black" ))
f. setWeight ( QFont::Black );
}
// Treat x-sheared fonts as italic
if (( m12 > -0.1 ) && ( m12 < 0.1 ) && ((( m21 > -5.0 ) && ( m21 < -0.1 )) || (( m21 > 0.1 ) && ( m21 < 5.0 )))) {
f. setItalic ( true );
}
return f;
}
//------------------------------------------------------------------------
// QOutputDev
//------------------------------------------------------------------------
QOutputDev::QOutputDev ( QWidget *parent, const char *name, int flags ) : QScrollView ( parent, name, WRepaintNoErase | WResizeNoErase | flags )
{
m_pixmap = 0;
m_painter = 0;
- m_use_string = true;
-
// create text object
m_text = new TextPage ( gFalse );
}
QOutputDev::~QOutputDev ( )
{
delete m_painter;
delete m_pixmap;
delete m_text;
}
void QOutputDev::startPage ( int /*pageNum*/, GfxState *state )
{
delete m_pixmap;
delete m_painter;
m_pixmap = new QPixmap ( lrint ( state-> getPageWidth ( )), lrint ( state-> getPageHeight ( )));
m_painter = new QPainter ( m_pixmap );
QPDFDBG( printf ( "NEW PIXMAP (%ld x %ld)\n", lrint ( state-> getPageWidth ( )), lrint ( state-> getPageHeight ( ))));
resizeContents ( m_pixmap-> width ( ), m_pixmap-> height ( ));
setContentsPos ( 0, 0 );
m_pixmap-> fill ( white ); // clear window
m_text-> clear ( ); // cleat text object
viewport ( )-> repaint ( );
}
void QOutputDev::endPage ( )
{
m_text-> coalesce ( );
delete m_painter;
m_painter = 0;
updateContents ( 0, 0, contentsWidth ( ), contentsHeight ( ));
}
void QOutputDev::drawLink ( Link *link, Catalog */*catalog*/ )
{
fp_t x1, y1, x2, y2, w;
link-> getBorder ( &x1, &y1, &x2, &y2, &w );
if ( w > 0 ) {
int x, y, dx, dy;
cvtUserToDev ( x1, y1, &x, &y );
cvtUserToDev ( x2, y2, &dx, &dy );
QPen oldpen = m_painter-> pen ( );
m_painter-> setPen ( blue );
m_painter-> drawRect ( x, y, dx, dy );
m_painter-> setPen ( oldpen );
}
}
void QOutputDev::saveState ( GfxState */*state*/ )
{
QPDFDBG( printf ( "SAVE (CLIP=%d/%d)\n", m_painter-> hasClipping ( ), !m_painter-> clipRegion ( ). isEmpty ( )));
m_painter-> save ( );
}
void QOutputDev::restoreState ( GfxState */*state*/ )
{
m_painter-> restore ( );
// m_painter-> setClipRegion ( QRect ( 0, 0, m_pixmap-> width ( ), m_pixmap-> height ( )));
// m_painter-> setClipping ( false );
QPDFDBG ( printf ( "RESTORE (CLIP=%d/%d)\n", m_painter-> hasClipping ( ), !m_painter-> clipRegion ( ). isEmpty ( )));
}
void QOutputDev::updateAll ( GfxState *state )
{
updateLineAttrs ( state, gTrue );
// updateFlatness ( state );
// updateMiterLimit ( state );
updateFillColor ( state );
updateStrokeColor ( state );
updateFont ( state );
}
void QOutputDev::updateCTM ( GfxState *state, fp_t /*m11*/, fp_t /*m12*/, fp_t /*m21*/, fp_t /*m22*/, fp_t /*m31*/, fp_t /*m32*/ )
{
updateLineAttrs ( state, gTrue );
}
void QOutputDev::updateLineDash ( GfxState *state )
{
updateLineAttrs ( state, gTrue );
}
void QOutputDev::updateFlatness ( GfxState */*state*/ )
{
// not supported
QPDFDBG( printf ( "updateFlatness not supported !\n" ));
}
void QOutputDev::updateLineJoin ( GfxState *state )
{
updateLineAttrs ( state, gFalse );
}
void QOutputDev::updateLineCap ( GfxState *state )
{
updateLineAttrs ( state, gFalse );
}
// unimplemented
void QOutputDev::updateMiterLimit ( GfxState */*state*/ )
{
QPDFDBG( printf ( "updateMiterLimit not supported !\n" ));
}
void QOutputDev::updateLineWidth ( GfxState *state )
{
updateLineAttrs ( state, gFalse );
}
void QOutputDev::updateLineAttrs ( GfxState *state, GBool updateDash )
{
fp_t *dashPattern;
int dashLength;
fp_t dashStart;
Qt::PenCapStyle cap;
Qt::PenJoinStyle join;
int width;
width = lrint ( state-> getTransformedLineWidth ( ));
switch ( state-> getLineCap ( )) {
case 0: cap = FlatCap; break;
case 1: cap = RoundCap; break;
case 2: cap = SquareCap; break;
default:
qWarning ( "Bad line cap style (%d)\n", state-> getLineCap ( ));
cap = FlatCap;
break;
}
switch (state->getLineJoin()) {
case 0: join = MiterJoin; break;
case 1: join = RoundJoin; break;
case 2: join = BevelJoin; break;
default:
qWarning ( "Bad line join style (%d)\n", state->getLineJoin ( ));
join = MiterJoin;
break;
}
state-> getLineDash ( &dashPattern, &dashLength, &dashStart );
QColor oldcol = m_painter-> pen ( ). color ( );
GfxRGB rgb;
state-> getStrokeRGB ( &rgb );
oldcol = q_col ( rgb );
m_painter-> setPen ( QPen ( oldcol, width, dashLength > 0 ? DashLine : SolidLine, cap, join ));
if ( updateDash && ( dashLength > 0 )) {
// Not supported by QT
/*
char dashList[20];
if (dashLength > 20)
dashLength = 20;
for ( int i = 0; i < dashLength; ++i ) {
dashList[i] = xoutRound(state->transformWidth(dashPattern[i]));
if (dashList[i] == 0)
dashList[i] = 1;
}
XSetDashes(display, strokeGC, xoutRound(dashStart), dashList, dashLength);
*/
}
}
void QOutputDev::updateFillColor ( GfxState *state )
{
GfxRGB rgb;
state-> getFillRGB ( &rgb );
m_painter-> setBrush ( q_col ( rgb ));
}
void QOutputDev::updateStrokeColor ( GfxState *state )
{
GfxRGB rgb;
state-> getStrokeRGB ( &rgb );