@@ -414,15 +414,19 @@ void QgsComposer::on_mActionPrint_activated(void)
414
414
415
415
// Overwrite translate
416
416
if ( mPrinter ->orientation () == QPrinter::Portrait ) {
417
+ std::cout << " Orientation portraint -> overwrite translate" << std::endl;
417
418
if (!f.open ( QIODevice::ReadWrite )) {
418
419
throw QgsIOException (tr (" Couldn't open " ) + f.name () + tr (" for read/write" ));
419
420
}
420
421
offset = 0 ;
421
422
found = false ;
422
423
423
- // Example:
424
+ // Example Qt3 :
424
425
// 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" );
426
430
427
431
while ( !f.atEnd () ) {
428
432
size = f.readLine ( buf, 100 );
@@ -438,14 +442,32 @@ void QgsComposer::on_mActionPrint_activated(void)
438
442
int trans;
439
443
440
444
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;
443
453
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) ) {
447
469
QMessageBox::warning (this , tr (" Error in Print" ), tr (" Cannot seek" ));
448
- } else {
470
+ } else {
449
471
/* Write spaces (for case the size > s.length() ) */
450
472
QString es;
451
473
es.fill (' ' , size-1 );
@@ -460,7 +482,6 @@ void QgsComposer::on_mActionPrint_activated(void)
460
482
QMessageBox::warning (this , tr (" Error in Print" ), tr (" Cannot overwrite translate" ));
461
483
}
462
484
f.flush ();
463
- }
464
485
}
465
486
} else {
466
487
QMessageBox::warning (this , tr (" Error in Print" ), tr (" Cannot find translate" ));
0 commit comments