|
50 | 50 |
|
51 | 51 | namespace |
52 | 52 | { |
| 53 | + using namespace glabels::model; |
| 54 | + |
53 | 55 | const uint32_t GDK_PIXBUF_MAGIC_NUMBER {0x47646b50}; |
54 | | - const double FONT_SCALE_FACTOR {0.75}; |
| 56 | + |
| 57 | + const double FONT_SCALE_FACTOR {0.75}; // In glabels-3, fonts were rendered at 75% of specified fontsize |
| 58 | + const Distance MARGIN_OFFSET { Distance::pt(3) }; // In glabels-3, margin was not accounted for in text baseline calculations |
55 | 59 |
|
56 | 60 | typedef enum |
57 | 61 | { |
@@ -463,35 +467,35 @@ namespace glabels::model |
463 | 467 | XmlLabelParser_3::parseObjectTextNode( const QDomElement &node ) |
464 | 468 | { |
465 | 469 | /* position attrs */ |
466 | | - const Distance x0 = XmlUtil::getLengthAttr( node, "x", 0.0 ); |
467 | | - const Distance y0 = XmlUtil::getLengthAttr( node, "y", 0.0 ); |
| 470 | + Distance x0 = XmlUtil::getLengthAttr( node, "x", 0.0 ); |
| 471 | + Distance y0 = XmlUtil::getLengthAttr( node, "y", 0.0 ); |
468 | 472 |
|
469 | 473 | /* size attrs */ |
470 | | - const Distance w = XmlUtil::getLengthAttr( node, "w", 0 ); |
471 | | - const Distance h = XmlUtil::getLengthAttr( node, "h", 0 ); |
| 474 | + Distance w = XmlUtil::getLengthAttr( node, "w", 0 ); |
| 475 | + Distance h = XmlUtil::getLengthAttr( node, "h", 0 ); |
472 | 476 |
|
473 | 477 | /* justify attr */ |
474 | | - const Qt::Alignment textHAlign = getHAlignmentAttr( node, "justify", Qt::AlignLeft ); |
| 478 | + Qt::Alignment textHAlign = getHAlignmentAttr( node, "justify", Qt::AlignLeft ); |
475 | 479 |
|
476 | 480 | /* valign attr */ |
477 | | - const Qt::Alignment textVAlign = getVAlignmentAttr( node, "valign", Qt::AlignTop ); |
| 481 | + Qt::Alignment textVAlign = getVAlignmentAttr( node, "valign", Qt::AlignTop ); |
478 | 482 |
|
479 | 483 | /* auto_shrink attr */ |
480 | | - const bool textAutoShrink = XmlUtil::getBoolAttr( node, "auto_shrink", false ); |
| 484 | + bool textAutoShrink = XmlUtil::getBoolAttr( node, "auto_shrink", false ); |
481 | 485 |
|
482 | 486 | /* affine attrs */ |
483 | | - const auto affineTransformation = parseAffineTransformation(node); |
| 487 | + auto affineTransformation = parseAffineTransformation(node); |
484 | 488 |
|
485 | 489 | /* shadow attrs */ |
486 | | - const bool shadowState = XmlUtil::getBoolAttr( node, "shadow", false ); |
487 | | - const Distance shadowX = XmlUtil::getLengthAttr( node, "shadow_x", 0.0 ); |
488 | | - const Distance shadowY = XmlUtil::getLengthAttr( node, "shadow_y", 0.0 ); |
489 | | - const double shadowOpacity = XmlUtil::getDoubleAttr( node, "shadow_opacity", 1.0 ); |
| 490 | + bool shadowState = XmlUtil::getBoolAttr( node, "shadow", false ); |
| 491 | + Distance shadowX = XmlUtil::getLengthAttr( node, "shadow_x", 0.0 ); |
| 492 | + Distance shadowY = XmlUtil::getLengthAttr( node, "shadow_y", 0.0 ); |
| 493 | + double shadowOpacity = XmlUtil::getDoubleAttr( node, "shadow_opacity", 1.0 ); |
490 | 494 |
|
491 | 495 | QString key = XmlUtil::getStringAttr( node, "shadow_color_field", "" ); |
492 | 496 | bool field_flag = !key.isEmpty(); |
493 | 497 | uint32_t color = XmlUtil::getUIntAttr( node, "shadow_color", 0 ); |
494 | | - const ColorNode shadowColorNode( field_flag, color, key ); |
| 498 | + ColorNode shadowColorNode( field_flag, color, key ); |
495 | 499 |
|
496 | 500 | /* font attrs */ |
497 | 501 | QString fontFamily = "Sans"; |
@@ -576,16 +580,32 @@ namespace glabels::model |
576 | 580 | } |
577 | 581 | const QString text = document.toPlainText(); |
578 | 582 |
|
| 583 | + // Compensate for differences in glabels-3 text baseline calculations |
| 584 | + switch ( textVAlign ) |
| 585 | + { |
| 586 | + case Qt::AlignVCenter: |
| 587 | + // No adjustment should be needed |
| 588 | + break; |
| 589 | + case Qt::AlignBottom: |
| 590 | + y0 += MARGIN_OFFSET; |
| 591 | + break; |
| 592 | + default: |
| 593 | + y0 -= MARGIN_OFFSET; |
| 594 | + break; |
| 595 | + } |
| 596 | + |
579 | 597 | auto textNode = new ModelTextObject( x0, y0, w, h, false /*lockAspectRatio*/, text, |
580 | 598 | fontFamily, fontSize, fontWeight, fontItalicFlag, false, |
581 | 599 | textColorNode, textHAlign, textVAlign, textWrapMode, textLineSpacing, |
582 | 600 | textAutoShrink, |
583 | 601 | affineTransformation, |
584 | 602 | shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode ); |
585 | 603 |
|
586 | | - // The size of the textnode does not fit the qt world. So it's needed to |
587 | | - // recalculate the size depending on the data. |
588 | | - textNode->setSize(textNode->naturalSize()); |
| 604 | + if ( (w.pt() == 0) || (h.pt() == 0) ) |
| 605 | + { |
| 606 | + // Do our best to autosize |
| 607 | + textNode->setSize(textNode->naturalSize()); |
| 608 | + } |
589 | 609 |
|
590 | 610 | return textNode; |
591 | 611 | } |
|
0 commit comments