Skip to content

Commit 4dbe0ad

Browse files
author
rblazek
committed
fixed ticket 345 (Cannot find translate)
git-svn-id: http://svn.osgeo.org/qgis/trunk@6142 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 9dd27fd commit 4dbe0ad

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

src/composer/qgscomposer.cpp

+30-9
Original file line numberDiff line numberDiff line change
@@ -414,15 +414,19 @@ void QgsComposer::on_mActionPrint_activated(void)
414414

415415
// Overwrite translate
416416
if ( mPrinter->orientation() == QPrinter::Portrait ) {
417+
std::cout << "Orientation portraint -> overwrite translate" << std::endl;
417418
if (!f.open( QIODevice::ReadWrite )) {
418419
throw QgsIOException(tr("Couldn't open ") + f.name() + tr(" for read/write"));
419420
}
420421
offset = 0;
421422
found = false;
422423

423-
//Example:
424+
//Example Qt3:
424425
//0 4008 translate 1 -1 scale/defM ...
425-
QRegExp rx ( "^0 [^ ]+ translate ([^ ]+ [^ ]+) scale/defM matrix CM d \\} d" );
426+
//QRegExp rx ( "^0 [^ ]+ translate ([^ ]+ [^ ]+) scale/defM matrix CM d \\} d" );
427+
//Example Qt4:
428+
//0 0 translate 0.239999 -0.239999 scale } def
429+
QRegExp rx ( "^0 [^ ]+ translate ([^ ]+ [^ ]+) scale \\} def" );
426430

427431
while ( !f.atEnd() ) {
428432
size = f.readLine ( buf, 100 );
@@ -438,14 +442,32 @@ void QgsComposer::on_mActionPrint_activated(void)
438442
int trans;
439443

440444
trans = (int) ( 72 * mComposition->paperHeight() / 25.4 );
441-
s.sprintf( "0 %d translate %s scale/defM matrix CM d } d", trans, (const char *)rx.cap(1).toLocal8Bit().data() );
442-
445+
std::cout << "trans = " << trans << std::endl;
446+
//Qt3:
447+
//s.sprintf( "0 %d translate %s scale/defM matrix CM d } d", trans, (const char *)rx.cap(1).toLocal8Bit().data() );
448+
//Qt4:
449+
s.sprintf( "0 %d translate %s scale } def\n", trans, (const char *)rx.cap(1).toLocal8Bit().data() );
450+
451+
452+
std::cout << "s.length() = " << s.length() << " size = " << size << std::endl;
443453
if ( s.length() > size ) {
444-
QMessageBox::warning(this, tr("Error in Print"), tr("Cannot format translate"));
445-
} else {
446-
if ( ! f.at(offset) ) {
454+
//QMessageBox::warning(this, tr("Error in Print"), tr("Cannot format translate"));
455+
// Move the content up
456+
int shift = s.length() - size;
457+
int last = f.size() + shift -1;
458+
for ( int i = last; i > offset + size; i-- )
459+
{
460+
f.at(i-shift);
461+
QByteArray ba = f.read(1);
462+
f.at(i);
463+
f.write(ba);
464+
}
465+
}
466+
467+
// Overwrite the row
468+
if ( ! f.at(offset) ) {
447469
QMessageBox::warning(this, tr("Error in Print"), tr("Cannot seek"));
448-
} else {
470+
} else {
449471
/* Write spaces (for case the size > s.length() ) */
450472
QString es;
451473
es.fill(' ', size-1 );
@@ -460,7 +482,6 @@ void QgsComposer::on_mActionPrint_activated(void)
460482
QMessageBox::warning(this, tr("Error in Print"), tr("Cannot overwrite translate"));
461483
}
462484
f.flush();
463-
}
464485
}
465486
} else {
466487
QMessageBox::warning(this, tr("Error in Print"), tr("Cannot find translate"));

0 commit comments

Comments
 (0)