This relates to Bug 2095 Note that a handful of translation strings did not merge properlypull/1/head
parent
9782548013
commit
d265f2381c
@ -1,7 +1,7 @@
|
||||
#MIN_CONFIG(3.0.0)
|
||||
KDE_ENABLE_HIDDEN_VISIBILITY
|
||||
|
||||
AM_INIT_AUTOMAKE(kbarcode, 2.0.6)
|
||||
AM_INIT_AUTOMAKE(kbarcode, 2.0.7)
|
||||
AC_C_BIGENDIAN
|
||||
AC_CHECK_KDEMAXPATHLEN
|
||||
|
||||
|
@ -1,427 +0,0 @@
|
||||
/***************************************************************************
|
||||
dsrichtext.cpp - description
|
||||
-------------------
|
||||
begin : Fre Okt 17 2003
|
||||
copyright : (C) 2003 by Dominik Seichter
|
||||
email : domseichter@web.de
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "dsrichtext.h"
|
||||
|
||||
#ifdef TQT_TEXT_BUG
|
||||
|
||||
// TQt includes
|
||||
#include <tqfontmetrics.h>
|
||||
#include <tqpainter.h>
|
||||
#include <tqregexp.h>
|
||||
|
||||
// for DSREPLACE
|
||||
#include "sqltables.h"
|
||||
|
||||
/*
|
||||
EXAMPLE TEXT:
|
||||
"<html><head><meta name=\"qrichtext\" content=\"1\" /></head><body style=\"font-size:10pt;font-family:Nimbus Sans l\">"
|
||||
"<p>A little bit <span style=\"font-style:italic;font-weight:600\">formated</span><span style=\"color:#4400ff\"> "
|
||||
"richtext</span> which should be printed to a <span style=\"font-weight:600\">TQPrinter</span> with <span style=\"text-decoration:underline\">TQSimpleRichText</span>. </p>"
|
||||
"<p><span style=\"font-family:Times New Roman;font-size:16pt\">Printing should work in ScreenResolution as well as in HighResolution, but as you can see it will only work in ScreenResolution.</span></p>"
|
||||
"</body></html>";
|
||||
|
||||
Another example
|
||||
<html><head><meta name="qrichtext" content="1" /></head><body style="font-size:10pt;font-family:Nimbus Sans l">
|
||||
<p align="center"><span style="font-size:12pt;font-weight:600;text-decoration:underline">Text test </span><span style="font-size:12pt;font-weight:600;text-decoration:underline;color:#ff0000">label</span></p>
|
||||
<p>Resolution <span style="font-weight:600">formated</span> 108dpi. This text & text should now overlap with the first line. 4 < 6a</p>
|
||||
<p><span style="font-family:Nimbus Sans L;font-weight:600">A</span><span style="font-family:Nimbus Sans L"> longer paragraph with some text, so that I can test wether wordwrap is working. Another "line" to test line spacing without a bigger font (like the one found in the next sentence) messing up the spacing.</span><span style="font-family:Courier [Adobe];font-size:16pt"> Some text "in" a bigger courier font.</span><span style="font-family:Nimbus Sans L"> Also this paragraph should be justified as blockquote.</span><span style="font-family:Nimbus Sans L;color:#ff0004"> I hope it works</span><span style="font-family:Nimbus Sans L"> and KBarcodes text redering will be better than the one found in TQt.</span></p>
|
||||
</body></html>
|
||||
|
||||
*/
|
||||
|
||||
DSRichText::DSRichText( const TQString & t )
|
||||
: text( t )
|
||||
{
|
||||
if( text.find("<html>") == -1 )
|
||||
text = "<html><head><meta name=\"qrichtext\" content=\"1\" /></head><body style=\"font-size:10pt;font-family:Nimbus Sans l\"><p>"
|
||||
+ t + "</p></body></html>";
|
||||
|
||||
//tqDebug( text );
|
||||
|
||||
start = end = pos = 0;
|
||||
x = y = 0;
|
||||
sx = sy = 1.0;
|
||||
m_base = TQFont();
|
||||
|
||||
TQString tmp = parse( text, "<body ", ">", 0 );
|
||||
if( !tmp.isNull() ) {
|
||||
pos += tmp.length();
|
||||
tmp = tmp.left( tmp.length() - 1 );
|
||||
tmp = tmp.mid( 5, tmp.length() - 5 );
|
||||
m_base = parseStyle( parse( tmp, "style=\"", "\"", pos ), &m_color );
|
||||
}
|
||||
|
||||
pos = text.find( "<p", 0 ); // initalize pos correctly
|
||||
while( parseParagraph() ); // empty while loop
|
||||
}
|
||||
|
||||
DSRichText::~DSRichText()
|
||||
{
|
||||
}
|
||||
|
||||
void DSRichText::initFormat( formated_word* f, int alignment )
|
||||
{
|
||||
f->text = TQString();
|
||||
f->line = false;
|
||||
f->alignment = alignment;
|
||||
f->font = m_base;
|
||||
f->color = m_color;
|
||||
}
|
||||
|
||||
void DSRichText::initLine( TQValueList<formated_line>* l )
|
||||
{
|
||||
formated_line li;
|
||||
li.width = 0;
|
||||
li.ascent = 0;
|
||||
li.leading = 0;
|
||||
li.lineSpacing = 0;
|
||||
li.line = false;
|
||||
l->append( li );
|
||||
}
|
||||
|
||||
void DSRichText::updateSpacing( TQValueList<formated_line>* l, TQFontMetrics* fm )
|
||||
{
|
||||
l->last().lineSpacing = (l->last().lineSpacing < fm->lineSpacing()) ? fm->lineSpacing() : l->last().lineSpacing;
|
||||
l->last().ascent = (l->last().ascent < fm->ascent()) ? fm->ascent() : l->last().ascent;
|
||||
l->last().leading = (l->last().leading < fm->leading()) ? fm->leading() : l->last().leading;
|
||||
}
|
||||
|
||||
void DSRichText::fillLines()
|
||||
{
|
||||
for( unsigned int z = 0; z < word_p.count(); z++ ) {
|
||||
WordList words = word_p[z];
|
||||
LineList lines;
|
||||
initLine( &lines );
|
||||
for( unsigned int i = 0; i < words.count(); i++ ) {
|
||||
formated_word word = words[i];
|
||||
lines.last().line = lines.last().line | word.line;
|
||||
|
||||
TQFontMetrics fm( word.font );
|
||||
updateSpacing( &lines, &fm );
|
||||
|
||||
int tw = fm.width( word.text );
|
||||
// word does not fit in the current line, create a new one
|
||||
if( lines.last().width + tw >= w )
|
||||
initLine( &lines );
|
||||
|
||||
// TODO: check here for words longer than one line
|
||||
lines.last().formats.append( word );
|
||||
lines.last().width += tw;
|
||||
}
|
||||
line_p.append( lines );
|
||||
}
|
||||
}
|
||||
|
||||
void DSRichText::draw( TQPainter* p )
|
||||
{
|
||||
/* don't try to draw if there is no space to draw */
|
||||
if( !w || !h )
|
||||
return;
|
||||
|
||||
fillLines();
|
||||
|
||||
painter = p;
|
||||
painter->save();
|
||||
painter->setClipRect( xpos, ypos, int(w*sx), int(h*sy), TQPainter::CoordPainter );
|
||||
|
||||
for( unsigned int z = 0; z < line_p.count(); z++ ) {
|
||||
LineList lines = line_p[z];
|
||||
if( lines.count() && z )
|
||||
y += int( lines[0].lineSpacing * 0.5);
|
||||
|
||||
for( unsigned int i = 0; i < lines.count(); i++ ) {
|
||||
formated_line l = lines[i];
|
||||
|
||||
if( l.formats.count() && l.formats[0].alignment == TQt::AlignJustify && i != lines.count() - 1 ) {
|
||||
// last line in a paragraph is not justified (in blocksatz mode)!
|
||||
drawJustified( &l );
|
||||
} else {
|
||||
for( unsigned int z = 0; z < l.formats.count(); z++ ) {
|
||||
formated_word f = l.formats[z];
|
||||
|
||||
painter->setFont( f.font );
|
||||
painter->setPen( TQPen( f.color ) );
|
||||
|
||||
int a = f.alignment;
|
||||
if( a == TQt::AlignRight ) {
|
||||
a = TQt::AlignLeft;
|
||||
if( !x )
|
||||
x = w - l.width;
|
||||
} else if( a == TQt::AlignHCenter ) {
|
||||
a = TQt::AlignLeft;
|
||||
if( !x )
|
||||
x = ( w - l.width ) / 2;
|
||||
}
|
||||
|
||||
int ya = yDeviation( &l );
|
||||
painter->drawText( xpos + int(x*sx), ypos + int((y+ya)*sy), int(l.width*sx), int(l.lineSpacing * sy), a, f.text );
|
||||
x += painter->fontMetrics().width( f.text );
|
||||
}
|
||||
}
|
||||
|
||||
x = 0;
|
||||
y += l.lineSpacing;
|
||||
}
|
||||
}
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
void DSRichText::drawJustified( formated_line* line )
|
||||
{
|
||||
int all = 0;
|
||||
for( unsigned int z = 0; z < line->formats.count(); z++ ) {
|
||||
line->formats[z].text = line->formats[z].text.stripWhiteSpace();
|
||||
TQFontMetrics fm( line->formats[z].font );
|
||||
all += fm.width( line->formats[z].text );
|
||||
}
|
||||
|
||||
int x = 0;
|
||||
int space = (w - all) / (line->formats.count() - 1);
|
||||
for( unsigned int z = 0; z < line->formats.count(); z++ ) {
|
||||
painter->setFont( line->formats[z].font );
|
||||
painter->setPen( TQPen( line->formats[z].color ) );
|
||||
|
||||
int ya = yDeviation( line );
|
||||
int tw = painter->fontMetrics().width(line->formats[z].text);
|
||||
painter->drawText( int(x*sx), int((y+ya)*sy), int(tw*sx), int(line->lineSpacing * sy), TQt::AlignAuto, line->formats[z].text );
|
||||
x += tw;
|
||||
x += space;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool DSRichText::parseParagraph()
|
||||
{
|
||||
int alignment = 0;
|
||||
formated_word f;
|
||||
TQString d = parse( text, "<p", "</p>", pos );
|
||||
//tqDebug("D=" + d );
|
||||
//tqDebug("POS=%i", pos );
|
||||
|
||||
pos += d.length();
|
||||
if( d.isNull() )
|
||||
return false;
|
||||
|
||||
d = parseParagraphTag( d, &alignment );
|
||||
|
||||
WordList words;
|
||||
TQString data;
|
||||
initFormat( &f, alignment );
|
||||
|
||||
if( d.isEmpty() ) {
|
||||
// found empty paragraph
|
||||
words.append( f );
|
||||
word_p.append( words );
|
||||
return true;
|
||||
}
|
||||
|
||||
for( unsigned int i = 0; i < d.length(); ) {
|
||||
if( d[i] == '<' || i == (d.length() - 1) ) {
|
||||
if( i == (d.length() - 1) )
|
||||
data.append( d[i] );
|
||||
|
||||
parseWords( data, &f, &words );
|
||||
initFormat( &f, alignment );
|
||||
data = TQString();
|
||||
|
||||
// bail out now, otherwise there is
|
||||
// and endless loop for e.g. <p>a</p>
|
||||
if( i == (d.length() - 1) )
|
||||
break;
|
||||
|
||||
if( d[i] == '<' ) {
|
||||
TQString span = d.mid( i, d.find( ">", i ) - i + 1 );
|
||||
i += span.length();
|
||||
|
||||
if( span.startsWith( "<span " ) ) {
|
||||
initFormat( &f, alignment );
|
||||
f.font = parseStyle( parse( span, "style=\"", "\"", 0 ), &f.color );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
data.append( d[i] );
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
word_p.append( words );
|
||||
return true;
|
||||
}
|
||||
|
||||
TQFont DSRichText::parseStyle( const TQString & s, TQColor* color )
|
||||
{
|
||||
TQString style = TQString( s );
|
||||
|
||||
style = style.left( style.length() - 1 );
|
||||
if( style.startsWith("style=\"" ) )
|
||||
style = style.mid( 7, style.length() - 7 );
|
||||
|
||||
TQFont f = m_base;
|
||||
*color = m_color;
|
||||
|
||||
for ( int i = 0; i < style.contains(';')+1; i++ ) {
|
||||
TQString s = style.section( ';', i, i );
|
||||
if( s.isEmpty() )
|
||||
continue;
|
||||
|
||||
if ( s.startsWith("font-size:" ) ) {
|
||||
f.setPointSize( s.mid(10, s.length() - 12).toInt() );
|
||||
} else if ( s.startsWith("font-family:" ) ) {
|
||||
f.setFamily( s.right( s.length() - 12 ) );
|
||||
} else if( s.startsWith( "color:" ) ) {
|
||||
color->setNamedColor( s.right( s.length() - 6 ) );
|
||||
} else if( s.startsWith("text-decoration:") ) {
|
||||
if( s.endsWith( "underline" ) )
|
||||
f.setUnderline( true );
|
||||
/*#if [[[TQT_VERSION IS DEPRECATED]]] >= 0x030200
|
||||
else if( s.endsWith( "overline" ) )
|
||||
f.setOverline( true );
|
||||
#endif */
|
||||
else if( s.endsWith( "line-through" ) )
|
||||
f.setStrikeOut( true );
|
||||
} else if( s.startsWith( "font-style:") ) {
|
||||
if( s.endsWith( "italic" ) || s.endsWith( "oblique" ) )
|
||||
f.setItalic( true );
|
||||
} else if( s.startsWith( "font-weight:" ) ) {
|
||||
bool ok = false;
|
||||
int n = s.right( s.length() - 12 ).toInt( &ok );
|
||||
if( s.endsWith( "bold" ) )
|
||||
f.setBold( true );
|
||||
else if( ok )
|
||||
f.setWeight( n / 8 ); // convert CSS values to TQt values
|
||||
}
|
||||
}
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
TQString DSRichText::parse( const TQString & t, const TQString & find, const TQString & find2, int start )
|
||||
{
|
||||
int s = t.find( find, start );
|
||||
if( s == -1 || s < start )
|
||||
return TQString();
|
||||
|
||||
int pend = t.find( find2, s + find.length() );
|
||||
if( pend == -1 || pend < (signed int)(s + find.length()) )
|
||||
return TQString();
|
||||
|
||||
TQString text = t.mid( s, pend - s + find2.length() );
|
||||
return text;
|
||||
}
|
||||
|
||||
void DSRichText::setX( int x )
|
||||
{
|
||||
xpos = x;
|
||||
}
|
||||
|
||||
void DSRichText::setY( int y )
|
||||
{
|
||||
ypos = y;
|
||||
}
|
||||
|
||||
void DSRichText::setWidth( int width )
|
||||
{
|
||||
w = width;
|
||||
}
|
||||
|
||||
void DSRichText::setHeight( int height )
|
||||
{
|
||||
h = height;
|
||||
}
|
||||
|
||||
int DSRichText::parseAlignment( const TQString & align )
|
||||
{
|
||||
TQString a = TQString( align );
|
||||
if( a.endsWith("\"") )
|
||||
a = a.left( a.length() - 1 );
|
||||
|
||||
if( a.startsWith("align=\"") )
|
||||
a = a.mid( 7, a.length() - 7 );
|
||||
|
||||
if( a == "left" )
|
||||
return TQt::AlignLeft;
|
||||
else if( a == "center" )
|
||||
return TQt::AlignHCenter;
|
||||
else if( a == "right" )
|
||||
return TQt::AlignRight;
|
||||
else if( a == "justify" )
|
||||
return TQt::AlignJustify;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void DSRichText::parseWords( const TQString & t, formated_word* w, WordList* words )
|
||||
{
|
||||
unsigned int p = 0;
|
||||
for( unsigned int i = 0; i < t.length(); i++ ) {
|
||||
if( (t[i].isSpace() && p != i) || i == t.length() - 1 ) {
|
||||
formated_word word = *w;
|
||||
|
||||
word.text = replaceEscapeSequences( t.mid( p, i + 1 - p ) );
|
||||
|
||||
p = i + 1;
|
||||
words->append( word );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline int DSRichText::yDeviation( const formated_line* line )
|
||||
{
|
||||
// leading = 1 (almost ever)
|
||||
// linespacing = leading + height
|
||||
// height = ascent + descent + 1
|
||||
if( line->lineSpacing != painter->fontMetrics().lineSpacing() ) {
|
||||
return line->ascent + line->leading - painter->fontMetrics().ascent() - painter->fontMetrics().leading();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
TQString DSRichText::replaceEscapeSequences( const TQString & t )
|
||||
{
|
||||
TQString tmp = TQString( t );
|
||||
tmp = tmp.replace( DSREPLACE( "<" ), "<" );
|
||||
tmp = tmp.replace( DSREPLACE( ">" ), ">" );
|
||||
tmp = tmp.replace( DSREPLACE( "&" ), "&" );
|
||||
tmp = tmp.replace( DSREPLACE( """ ), "\"" );
|
||||
return tmp;
|
||||
}
|
||||
|
||||
TQString DSRichText::parseParagraphTag( const TQString &t, int* alignment )
|
||||
{
|
||||
TQString d = TQString( t );
|
||||
if( d.startsWith("<p>") ) {
|
||||
d = d.mid( 3, d.length() - 3 );
|
||||
} else if( d.startsWith("<p ") ) {
|
||||
*alignment = parseAlignment( parse( d, "align=\"", "\"", 0 ) );
|
||||
if( d.contains( ">" ) ) {
|
||||
int x = d.find(">" ) + 1;
|
||||
d = d.mid( x, d.length() - x );
|
||||
}
|
||||
}
|
||||
|
||||
if( d.endsWith("</p>") )
|
||||
d = d.left( d.length() - 4 ); // strlen("</p>");
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
#endif // TQT_TEXT_BUG
|
||||
|
||||
|
@ -1,193 +0,0 @@
|
||||
/***************************************************************************
|
||||
dsrichtext.h - description
|
||||
-------------------
|
||||
begin : Fre Okt 17 2003
|
||||
copyright : (C) 2003 by Dominik Seichter
|
||||
email : domseichter@web.de
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef DSRICHTEXT_H
|
||||
#define DSRICHTEXT_H
|
||||
|
||||
#define TQT_TEXT_BUG
|
||||
/*#undef TQT_TEXT_BUG*/
|
||||
#ifdef TQT_TEXT_BUG
|
||||
|
||||
#include <tqcolor.h>
|
||||
#include <tqfont.h>
|
||||
#include <tqstring.h>
|
||||
#include <tqvaluelist.h>
|
||||
|
||||
class DSRichText;
|
||||
|
||||
/** This class represents one word,
|
||||
* formated with a font, a color and an
|
||||
* alignment.
|
||||
*/
|
||||
struct formated_word {
|
||||
TQString text;
|
||||
TQFont font;
|
||||
TQColor color;
|
||||
int alignment;
|
||||
bool line;
|
||||
};
|
||||
|
||||
typedef TQValueList<formated_word> WordList;
|
||||
|
||||
/** This structure represents a single line.
|
||||
* Every line contains a list of formated_words.
|
||||
* Wordwrapping has been applied before the line
|
||||
* was created.
|
||||
* lineSpacing, ascent and leading come from the
|
||||
* biggest font in the line.
|
||||
*/
|
||||
struct formated_line {
|
||||
int width;
|
||||
int lineSpacing;
|
||||
int ascent;
|
||||
int leading;
|
||||
bool line;
|
||||
|
||||
WordList formats;
|
||||
};
|
||||
typedef TQValueList<formated_line> LineList;
|
||||
|
||||
class TQColor;
|
||||
class TQPainter;
|
||||
|
||||
/** A richtext rendering class, which draws a piece
|
||||
* of HTML formated richtext on any TQPainter.
|
||||
* This class works with all printer resolutions compared
|
||||
* to the buggy TQSimpleRichText
|
||||
*
|
||||
* rendering the richtext happens in 3 steps:
|
||||
* <ul>
|
||||
* <li> the HTML data is parsed into text_format structures. Each
|
||||
* of these text_format structures may represend multiple lines, but
|
||||
* also single words. This depends on how long a formated text is.
|
||||
* this step happens in the constructor and in parseParagraph()</li>
|
||||
* <li> the text_format structures are parsed into line structures.
|
||||
* In this step the wordwrapping is calculated. Each line structure
|
||||
* has again text_format structures. This is necessary because a line
|
||||
* of text may of course contain different formattings. A line struct is always
|
||||
* a single line of drawn text, not more and not less.
|
||||
* happens in draw() and fillLines()</li>
|
||||
* <li> the line structure is drawn line by line using TQPainter.
|
||||
* happens in draw()</li>
|
||||
* </ul>
|
||||
*
|
||||
* Printing to the screen is easy and the usage does not differ from
|
||||
* TQSimpleRichText. Drawing on TQPrinter is a little bit more complicated.
|
||||
* The most important thing is that you may not use TQPainter::scale().
|
||||
* A small example on how to print on a TQPrinter:
|
||||
* <pre>
|
||||
* TQPrinter printer( TQPrinter::HighResolution );
|
||||
* TQPainter painter( &printer );
|
||||
* TQPaintDeviceMetrics metrics( &printer );
|
||||
* double scalex = (double)metrics.logicalDpiX() / (double)TQPaintDevice::x11AppDpiX();
|
||||
* double scaley = (double)metrics.logicalDpiY() / (double)TQPaintDevice::x11AppDpiY();
|
||||
*
|
||||
* DSRichText dsr( "<html><p>Hallo World</p></html>" );
|
||||
* dsr.setWidth( 200 ); // in screenresolution coordinates
|
||||
* dsr.setHeight( 80 ); // in screenresolution coordinates
|
||||
* painter.translate( 10 * scalex, 10 * scaley ); // draw at 10, 10 instead of 0, 0
|
||||
* dsr.scale( scalex, scaley );
|
||||
* dsr.draw( &painter );
|
||||
* </pre>
|
||||
*
|
||||
*@author Dominik Seichter
|
||||
*/
|
||||
class DSRichText {
|
||||
public:
|
||||
/** construct a DSRichText object. @p t is formated text as produces by TQTextEdit.
|
||||
*/
|
||||
DSRichText( const TQString & t );
|
||||
~DSRichText();
|
||||
|
||||
void setX( int x );
|
||||
void setY( int y );
|
||||
|
||||
/** draw the formated text on the TQPainter* @p p
|
||||
*/
|
||||
void draw( TQPainter* p );
|
||||
/** set the width of the clipping rectangle
|
||||
*/
|
||||
void setWidth( int width );
|
||||
/** set the height of the clipping rectangle
|
||||
*/
|
||||
void setHeight( int height );
|
||||
/** scale everything. This is necessary to print on devices
|
||||
* with another resolution than the screen. TQPainter::scale() won't work.
|
||||
*/
|
||||
void setScale( double x, double y ) {
|
||||
sx = x; sy = y;
|
||||
};
|
||||
|
||||
private:
|
||||
/** parse a single pare of <p></p> elements
|
||||
*/
|
||||
bool parseParagraph();
|
||||
/** remove <p> and </p> from the TQString @p t and return it.
|
||||
* This function is also responsible for getting the
|
||||
* correct alignment of the paragraph.
|
||||
*/
|
||||
TQString parseParagraphTag( const TQString & t, int* alignment );
|
||||
/** parse the align attribute of a <p> tag and return the corresponding TQt alignment value.
|
||||
*/
|
||||
int parseAlignment( const TQString & align );
|
||||
/** parse the css style attribute of a <span> tag and return a matching TQFont for these
|
||||
* style. The font color is saved in the TQColor* @p color.
|
||||
*/
|
||||
TQFont parseStyle( const TQString & s, TQColor* color );
|
||||
TQString parse( const TQString & t, const TQString & find, const TQString & end, int start );
|
||||
void parseWords( const TQString & t, formated_word* w, WordList* words );
|
||||
void initFormat( formated_word* f, int alignment );
|
||||
void initLine( TQValueList<formated_line>* l );
|
||||
void updateSpacing( TQValueList<formated_line>* l, TQFontMetrics* fm );
|
||||
/** draw the line @p line justified as blockquote
|
||||
*/
|
||||
void drawJustified( formated_line* line );
|
||||
/** calculate the y-deviation needed, because of different font sizes in this line
|
||||
*/
|
||||
inline int yDeviation( const formated_line* line );
|
||||
/** replace HTML escape sequences such as < to their real character meaning (i.e. < )
|
||||
*/
|
||||
TQString replaceEscapeSequences( const TQString & t );
|
||||
|
||||
/** fill the line structures with data
|
||||
*/
|
||||
void fillLines();
|
||||
|
||||
int pos; // current position in text
|
||||
int start; // start of a tag
|
||||
int end; // end of a tag
|
||||
int x; // x position
|
||||
int y; // y position
|
||||
int w; // width of the text element
|
||||
int h; // height of the text element
|
||||
int xpos; // x position at the beginning
|
||||
int ypos; // y position at the beginning
|
||||
|
||||
double sx;
|
||||
double sy;
|
||||
|
||||
TQString text;
|
||||
TQFont m_base;
|
||||
TQColor m_color;
|
||||
TQPainter* painter;
|
||||
|
||||
TQValueList<LineList> line_p;
|
||||
TQValueList<WordList> word_p;
|
||||
};
|
||||
|
||||
#endif // TQT_TEXT_BUG
|
||||
#endif
|
@ -1,620 +0,0 @@
|
||||
f/***************************************************************************
|
||||
barcode.cpp - description
|
||||
-------------------
|
||||
begin : Die Apr 23 2002
|
||||
copyright : (C) 2002 by Dominik Seichter
|
||||
email : domseichter@web.de
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "sqltables.h"
|
||||
#include "barcodecache.h"
|
||||
|
||||
#include "mybarcode.h"
|
||||
#include <stdio.h>
|
||||
|
||||
// TQt includes
|
||||
#include <tqdir.h>
|
||||
#include <tqpainter.h>
|
||||
#include <tqpaintdevicemetrics.h>
|
||||
#include <tqsqlquery.h>
|
||||
|
||||
// KDE includes
|
||||
#include <tdeapplication.h>
|
||||
#include <tdeconfig.h>
|
||||
#include <tdelocale.h>
|
||||
#include <tdemessagebox.h>
|
||||
#include <kprocess.h>
|
||||
#include <kstandarddirs.h>
|
||||
#include <tdetempfile.h>
|
||||
|
||||
#define BARCODE_MARGIN 10 /* Margin added by GNU Barcode to the barcodes */
|
||||
|
||||
TQValueList<barcodeFormat> codes;
|
||||
|
||||
void init() {
|
||||
BarCode::setHaveBarcode();
|
||||
}
|
||||
|
||||
bool barcodeData::operator==( const struct barcodeData d ) const {
|
||||
bool b = ( value == d.value && type == d.type &&
|
||||
scale == d.scale && text == d.text );
|
||||
|
||||
if( BarCode::hasFeature( type, TBARCODEADV ) )
|
||||
b = ( b && tbarcode == d.tbarcode );
|
||||
|
||||
if( BarCode::hasFeature( type, DATAMATRIX ) )
|
||||
b = ( b && datamatrix == d.datamatrix );
|
||||
|
||||
if( BarCode::hasFeature( type, PDF417BARCODE ) )
|
||||
b = ( b && pdf417 == d.pdf417 );
|
||||
|
||||
return b;
|
||||
};
|
||||
|
||||
BarCode::BarCode( const barcodeData* data )
|
||||
{
|
||||
barcode = *data;
|
||||
m_index = 0;
|
||||
}
|
||||
|
||||
BarCode::BarCode()
|
||||
{
|
||||
fillDefault( &barcode );
|
||||
m_index = 0;
|
||||
}
|
||||
|
||||
BarCode::~BarCode()
|
||||
{
|
||||
}
|
||||
|
||||
const TQPixmap BarCode::pixmap()
|
||||
{
|
||||
if( p.isNull() )
|
||||
createBarcode( &p, TDEApplication::desktop() );
|
||||
|
||||
if( p.isNull() ) {
|
||||
KMessageBox::error( 0, "<qt>" + i18n("Barcode not valid!") + "<br>" + barcode.value + "</qt>" );
|
||||
barcode.valid = false;
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
bool BarCode::createPixmap( TQPixmap* target, int resx, int resy )
|
||||
{
|
||||
KTempFile* output = new KTempFile( TQString(), ".ps" );;
|
||||
output->file()->close();
|
||||
|
||||
KTempFile* input = new KTempFile( TQString(), ".pbm" );
|
||||
input->file()->close();
|
||||
|
||||
m_value = createSequence( barcode.value );
|
||||
|
||||
if( BarCode::hasFeature( barcode.type, PDF417 ) ) {
|
||||
if(!createPdf417( output )) {
|
||||
cleanUp( output, input, target );
|
||||
return false;
|
||||
}
|
||||
} else if( BarCode::hasFeature( barcode.type, TBARCODE ) ) {
|
||||
if(!createTBarcode( output )) {
|
||||
cleanUp( output, input, target );
|
||||
return false;
|
||||
}
|
||||
} else { // if( BarCode::hasFeature( barcode.type, GNU_BARCODE ) ) {
|
||||
TQString flag = barcode.text ? "" : "-n";
|
||||
|
||||
KShellProcess proc;
|
||||
proc << "barcode" << "-E"
|
||||
<< "-b" << KShellProcess::quote( m_value ) << flag
|
||||
<< "-e" << barcode.type << "-o" << output->name();
|
||||
|
||||
proc.start( TDEProcess::Block, TDEProcess::NoCommunication );
|
||||
proc.resume();
|
||||
|
||||
if( proc.exitStatus() ) {
|
||||
cleanUp( output, input, target );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
TQFileInfo fi( output->name() );
|
||||
// if file size = 0, error in generation
|
||||
if( !fi.size() ) {
|
||||
cleanUp( output, input, target );
|
||||
return false;
|
||||
}
|
||||
|
||||
TQSize s = getBoundingBox( output->name() );
|
||||
double sw = (double)s.width()/72 * resx;
|
||||
double sh = (double)s.height()/72 * resy;
|
||||
|
||||
KShellProcess proc2;
|
||||
proc2 << "gs" << TQString("-g%1x%2").arg(int(sw*(double)barcode.scale)).arg(int(sh*(double)barcode.scale))
|
||||
<< "-r" + TQString::number( resx*(double)barcode.scale ) + "x" + TQString::number( resy*(double)barcode.scale )
|
||||
<< "-sDEVICE=pbmraw" << "-sOutputFile=" + input->name() << "-sNOPAUSE"
|
||||
<< "-q " + output->name() << "-c showpage" << "-c quit";
|
||||
|
||||
proc2.start( TDEProcess::Block, TDEProcess::NoCommunication );
|
||||
proc2.resume();
|
||||
|
||||
if( proc2.exitStatus() ) {
|
||||
cleanUp( output, input, target );
|
||||
return false;
|
||||
}
|
||||
|
||||
target->load( input->name(), "PBM" );
|
||||
// BarcodeCache::instance()->write( barcode, resx, resy, target, m_value );
|
||||
|
||||
input->unlink();
|
||||
output->unlink();
|
||||
|
||||
delete output;
|
||||
delete input;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void BarCode::createBarcode( TQPixmap* target, TQPaintDevice* device )
|
||||
{
|
||||
TQPaintDeviceMetrics pdm( device );
|
||||
int resx = pdm.logicalDpiX();
|
||||
int resy = pdm.logicalDpiY();
|
||||
|
||||
TQString value = createSequence( barcode.value );
|
||||
TQPixmap* cached = 0;//BarcodeCache::instance()->read( barcode, resx, resy, value );
|
||||
|
||||
// no matching barcode found in cache
|
||||
if( !cached ) {
|
||||
if( !createPixmap( target, resx, resy ) )
|
||||
return;
|
||||
} else |