diff --git a/glabels/ObjectEditor.cpp b/glabels/ObjectEditor.cpp
index 17c93ee..fd40e43 100644
--- a/glabels/ObjectEditor.cpp
+++ b/glabels/ObjectEditor.cpp
@@ -246,6 +246,7 @@ namespace glabels
textVAlignGroup->button( mObject->textVAlign() )->setChecked( true );
textWrapModeCombo->setCurrentIndex( wrapIndex );
textLineSpacingSpin->setValue( mObject->textLineSpacing() );
+ textAutoShrinkCheck->setChecked( mObject->textAutoShrink() );
textEdit->setText( mObject->text() );
mBlocked = false;
@@ -718,6 +719,7 @@ namespace glabels
mObject->setTextVAlign( Qt::AlignmentFlag( textVAlignGroup->checkedId() ) );
mObject->setTextWrapMode( wrapMode );
mObject->setTextLineSpacing( textLineSpacingSpin->value() );
+ mObject->setTextAutoShrink( textAutoShrinkCheck->isChecked() );
mObject->setText( textEdit->toPlainText() );
mBlocked = false;
diff --git a/glabels/ui/ObjectEditor.ui b/glabels/ui/ObjectEditor.ui
index 6e7d245..c2d366d 100644
--- a/glabels/ui/ObjectEditor.ui
+++ b/glabels/ui/ObjectEditor.ui
@@ -32,6 +32,41 @@
Form
+ -
+
+
-
+
+
+
+ 0
+ 0
+
+
+
+
+
+
+ :/icons/24x24/actions/glabels-object-properties.png
+
+
+
+ -
+
+
+
+ Sans Serif
+ 10
+ 75
+ true
+
+
+
+ Object properties
+
+
+
+
+
-
@@ -297,6 +332,13 @@
+ -
+
+
+ Allow printing to shrink text to fit object
+
+
+
@@ -331,14 +373,14 @@
- -
+
-
Style:
- -
+
-
-
@@ -418,7 +460,7 @@
- -
+
-
Color:
@@ -455,7 +497,7 @@
- -
+
-
-
@@ -1476,41 +1518,6 @@
- -
-
-
-
-
-
-
- 0
- 0
-
-
-
-
-
-
- :/icons/24x24/actions/glabels-object-properties.png
-
-
-
- -
-
-
-
- Sans Serif
- 10
- 75
- true
-
-
-
- Object properties
-
-
-
-
-
@@ -1631,7 +1638,7 @@
132
- 248
+ 247
396
@@ -1758,8 +1765,8 @@
onLineControlsChanged()
- 119
- 106
+ 178
+ 143
392
@@ -1774,8 +1781,8 @@
onLineControlsChanged()
- 119
- 106
+ 137
+ 179
1
@@ -1790,8 +1797,8 @@
onFillControlsChanged()
- 119
- 106
+ 136
+ 263
6
@@ -1806,8 +1813,8 @@
onPositionControlsChanged()
- 119
- 106
+ 159
+ 142
399
@@ -1822,8 +1829,8 @@
onPositionControlsChanged()
- 119
- 106
+ 159
+ 179
325
@@ -1838,8 +1845,8 @@
onRectSizeControlsChanged()
- 119
- 111
+ 159
+ 265
3
@@ -1854,8 +1861,8 @@
onRectSizeControlsChanged()
- 119
- 111
+ 159
+ 302
0
@@ -1870,8 +1877,8 @@
onResetImageSize()
- 119
- 111
+ 210
+ 372
4
@@ -1902,8 +1909,8 @@
onShadowControlsChanged()
- 119
- 106
+ 165
+ 142
398
@@ -1918,8 +1925,8 @@
onShadowControlsChanged()
- 119
- 106
+ 165
+ 179
294
@@ -1934,8 +1941,8 @@
onShadowControlsChanged()
- 119
- 106
+ 142
+ 215
399
@@ -1950,8 +1957,8 @@
onShadowControlsChanged()
- 119
- 106
+ 159
+ 252
399
@@ -1966,8 +1973,8 @@
onLineSizeControlsChanged()
- 119
- 116
+ 174
+ 456
5
@@ -1982,8 +1989,8 @@
onLineSizeControlsChanged()
- 119
- 116
+ 174
+ 493
1
@@ -1998,8 +2005,8 @@
onImageFileButtonClicked()
- 119
- 106
+ 133
+ 175
394
@@ -2014,8 +2021,8 @@
onImageKeySelected(QString)
- 119
- 106
+ 302
+ 175
397
@@ -2062,8 +2069,8 @@
onBarcodeControlsChanged()
- 119
- 106
+ 178
+ 172
4
@@ -2078,8 +2085,8 @@
onBarcodeControlsChanged()
- 105
- 106
+ 164
+ 204
1
@@ -2094,8 +2101,8 @@
onBarcodeControlsChanged()
- 100
- 106
+ 126
+ 239
1
@@ -2110,8 +2117,8 @@
onBarcodeControlsChanged()
- 119
- 112
+ 132
+ 325
398
@@ -2126,8 +2133,8 @@
onBarcodeInsertFieldKeySelected(QString)
- 119
- 112
+ 239
+ 400
403
@@ -2142,8 +2149,8 @@
onBarcodeControlsChanged()
- 119
- 106
+ 178
+ 140
5
@@ -2167,6 +2174,22 @@
+
+ textAutoShrinkCheck
+ toggled(bool)
+ ObjectEditor
+ onTextControlsChanged()
+
+
+ 130
+ 431
+
+
+ 359
+ 636
+
+
+
onChanged()
diff --git a/model/ModelObject.cpp b/model/ModelObject.cpp
index 111fc32..637352c 100644
--- a/model/ModelObject.cpp
+++ b/model/ModelObject.cpp
@@ -634,6 +634,26 @@ namespace glabels
}
+ ///
+ /// Virtual Text Auto Shrink Property Default Getter
+ /// (Overridden by concrete class)
+ ///
+ bool ModelObject::textAutoShrink() const
+ {
+ return false;
+ }
+
+
+ ///
+ /// Virtual Text Auto Shrink Property Default Setter
+ /// (Overridden by concrete class)
+ ///
+ void ModelObject::setTextAutoShrink( bool value )
+ {
+ // empty
+ }
+
+
///
/// Virtual Filename Node Property Default Getter
/// (Overridden by concrete class)
diff --git a/model/ModelObject.h b/model/ModelObject.h
index 3a571a4..6af51e8 100644
--- a/model/ModelObject.h
+++ b/model/ModelObject.h
@@ -265,6 +265,13 @@ namespace glabels
virtual void setTextLineSpacing( double value );
+ //
+ // Virtual Text Property: textAutoShrink
+ //
+ virtual bool textAutoShrink() const;
+ virtual void setTextAutoShrink( bool value );
+
+
///////////////////////////////////////////////////////////////
// Image Properties Virtual Interface
///////////////////////////////////////////////////////////////
diff --git a/model/ModelTextObject.cpp b/model/ModelTextObject.cpp
index c20336e..434d48b 100644
--- a/model/ModelTextObject.cpp
+++ b/model/ModelTextObject.cpp
@@ -71,6 +71,7 @@ namespace glabels
mTextVAlign = Qt::AlignTop;
mTextWrapMode = QTextOption::WordWrap;
mTextLineSpacing = 1;
+ mTextAutoShrink = false;
}
@@ -92,6 +93,7 @@ namespace glabels
Qt::Alignment textVAlign,
QTextOption::WrapMode textWrapMode,
double textLineSpacing,
+ bool textAutoShrink,
const QMatrix& matrix,
bool shadowState,
const Distance& shadowX,
@@ -124,6 +126,7 @@ namespace glabels
mTextVAlign = textVAlign;
mTextWrapMode = textWrapMode;
mTextLineSpacing = textLineSpacing;
+ mTextAutoShrink = textAutoShrink;
update(); // Initialize cached editor layouts
}
@@ -146,6 +149,7 @@ namespace glabels
mTextVAlign = object->mTextVAlign;
mTextWrapMode = object->mTextWrapMode;
mTextLineSpacing = object->mTextLineSpacing;
+ mTextAutoShrink = object->mTextAutoShrink;
update(); // Initialize cached editor layouts
}
@@ -428,6 +432,29 @@ namespace glabels
}
+ ///
+ /// TextAutoShrink Property Getter
+ ///
+ bool ModelTextObject::textAutoShrink() const
+ {
+ return mTextAutoShrink;
+ }
+
+
+ ///
+ /// TextAutoShrink Property Setter
+ ///
+ void ModelTextObject::setTextAutoShrink( bool value )
+ {
+ if ( mTextAutoShrink != value )
+ {
+ mTextAutoShrink = value;
+ update();
+ emit changed();
+ }
+ }
+
+
///
/// NaturalSize Property Getter
///
@@ -677,7 +704,7 @@ namespace glabels
QFont font;
font.setFamily( mFontFamily );
- font.setPointSizeF( mFontSize );
+ font.setPointSizeF( mTextAutoShrink ? autoShrinkFontSize( record ) : mFontSize );
font.setWeight( mFontWeight );
font.setItalic( mFontItalicFlag );
font.setUnderline( mFontUnderlineFlag );
@@ -758,5 +785,72 @@ namespace glabels
painter->restore();
}
+
+ ///
+ /// Determine auto shrink font size
+ ///
+ double
+ ModelTextObject::autoShrinkFontSize( merge::Record* record ) const
+ {
+ QFont font;
+ font.setFamily( mFontFamily );
+ font.setWeight( mFontWeight );
+ font.setItalic( mFontItalicFlag );
+ font.setUnderline( mFontUnderlineFlag );
+
+ QTextOption textOption;
+ textOption.setAlignment( mTextHAlign );
+ textOption.setWrapMode( mTextWrapMode );
+
+ QTextDocument document( mText.expand( record ) );
+
+ double candidateSize = mFontSize;
+ while ( candidateSize > 1.0 )
+ {
+ font.setPointSizeF( candidateSize );
+
+ // Line spacing is affected by font size
+ QFontMetricsF fontMetrics( font );
+ double dy = fontMetrics.lineSpacing() * mTextLineSpacing;
+
+ // Do candidate layouts, letting text flow according to wrap mode
+ double x = 0;
+ double y = 0;
+ QRectF layoutsRect;
+ for ( int i = 0; i < document.blockCount(); i++ )
+ {
+ QTextLayout layout( document.findBlockByNumber(i).text() );
+
+ layout.setFont( font );
+ layout.setTextOption( textOption );
+ layout.setCacheEnabled(true);
+
+ layout.beginLayout();
+ for ( QTextLine l = layout.createLine(); l.isValid(); l = layout.createLine() )
+ {
+ l.setLineWidth( mW.pt() - 2*marginPts );
+ l.setPosition( QPointF( x, y ) );
+ y += dy;
+ }
+ layout.endLayout();
+
+ layoutsRect = layout.boundingRect().united( layoutsRect );
+ }
+
+ // Did this candidate fit in our object's bounding box?
+ if ( ( (layoutsRect.width() + 2*marginPts) <= mW.pt() ) &&
+ ( (layoutsRect.height() + 2*marginPts) <= mH.pt() ) )
+ {
+ break;
+ }
+
+ // If not, let's try a slightly smaller font size
+ candidateSize -= 0.5;
+ }
+
+ return candidateSize;
+ }
+
+
}
}
diff --git a/model/ModelTextObject.h b/model/ModelTextObject.h
index 654488c..1ab62c6 100644
--- a/model/ModelTextObject.h
+++ b/model/ModelTextObject.h
@@ -61,6 +61,7 @@ namespace glabels
Qt::Alignment textVAlign,
QTextOption::WrapMode textWrapMode,
double textLineSpacing,
+ bool textAutoShrink,
const QMatrix& matrix = QMatrix(),
bool shadowState = false,
const Distance& shadowX = 0,
@@ -160,6 +161,13 @@ namespace glabels
void setTextLineSpacing( double value ) override;
+ //
+ // Text Property: textAutoShrink
+ //
+ bool textAutoShrink() const override;
+ void setTextAutoShrink( bool value ) override;
+
+
//
// Property: naturalSize
//
@@ -191,6 +199,7 @@ namespace glabels
void drawTextInEditor( QPainter* painter, const QColor& color ) const;
void drawText( QPainter* painter, const QColor&color, merge::Record* record ) const;
QString expandText( QString text, merge::Record* record ) const;
+ double autoShrinkFontSize( merge::Record* record ) const;
///////////////////////////////////////////////////////////////
@@ -208,6 +217,7 @@ namespace glabels
Qt::Alignment mTextVAlign;
QTextOption::WrapMode mTextWrapMode;
double mTextLineSpacing;
+ bool mTextAutoShrink;
QList mEditorLayouts;
QPainterPath mHoverPath;
diff --git a/model/XmlLabelCreator.cpp b/model/XmlLabelCreator.cpp
index 21af581..87b3114 100644
--- a/model/XmlLabelCreator.cpp
+++ b/model/XmlLabelCreator.cpp
@@ -338,10 +338,11 @@ namespace glabels
XmlUtil::setBoolAttr( node, "font_underline", object->fontUnderlineFlag() );
/* text attrs */
- XmlUtil::setDoubleAttr( node, "line_spacing", object->textLineSpacing() );
XmlUtil::setAlignmentAttr( node, "align", object->textHAlign() );
XmlUtil::setAlignmentAttr( node, "valign", object->textVAlign() );
XmlUtil::setWrapModeAttr( node, "wrap", object->textWrapMode() );
+ XmlUtil::setDoubleAttr( node, "line_spacing", object->textLineSpacing() );
+ XmlUtil::setBoolAttr( node, "auto_shrink", object->textAutoShrink() );
/* affine attrs */
createAffineAttrs( node, object );
diff --git a/model/XmlLabelParser.cpp b/model/XmlLabelParser.cpp
index f36dc02..5fbced5 100644
--- a/model/XmlLabelParser.cpp
+++ b/model/XmlLabelParser.cpp
@@ -633,6 +633,7 @@ namespace glabels
Qt::Alignment textHAlign = XmlUtil::getAlignmentAttr( node, "align", Qt::AlignLeft );
Qt::Alignment textVAlign = XmlUtil::getAlignmentAttr( node, "valign", Qt::AlignTop );
QTextOption::WrapMode textWrapMode = XmlUtil::getWrapModeAttr( node, "wrap", QTextOption::WordWrap );
+ bool textAutoShrink = XmlUtil::getBoolAttr( node, "auto_shrink", false );
/* affine attrs */
double a[6];
@@ -682,6 +683,7 @@ namespace glabels
text,
fontFamily, fontSize, fontWeight, fontItalicFlag, fontUnderlineFlag,
textColorNode, textHAlign, textVAlign, textWrapMode, textLineSpacing,
+ textAutoShrink,
QMatrix( a[0], a[1], a[2], a[3], a[4], a[5] ),
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode );
}
diff --git a/translations/glabels_C.ts b/translations/glabels_C.ts
index 094f839..b9ea9e8 100644
--- a/translations/glabels_C.ts
+++ b/translations/glabels_C.ts
@@ -346,235 +346,240 @@
-
+
Text
-
+
Layout
-
+
Alignment:
-
+
Line spacing:
-
+
Wrap mode:
-
+
Word
-
+
+ Allow printing to shrink text to fit object
+
+
+
+
Font
-
+
Family:
-
+
Size:
-
+
Style:
-
-
-
-
-
+
+
+
+
+
Color:
-
+
Editor
-
+
Barcode
-
+
Style
-
+
Type:
-
+
Show text
-
+
Checksum
-
+
Barcode data
-
+
Image
-
+
File
-
-
+
+
None
-
+
Anywhere
-
+
Select File...
-
+
or
-
+
Select Merge Field...
-
+
Line/Fill
-
+
Line
-
-
+
+
Width:
-
+
Fill
-
+
Position/Size
-
+
Position
-
+
X:
-
+
Y:
-
-
+
+
Size
-
+
Length:
-
+
Angle:
-
+
Original size:
-
+
Reset
-
+
Lock aspect ratio
-
+
Height:
-
-
+
+
Shadow
-
+
X offset:
-
+
Y offset:
-
+
Opacity:
-
+
Object properties
@@ -2163,25 +2168,15 @@
-
+
Box object properties
-
-
-
-
- line/fill
-
-
-
-
-
- position/size
+ line/fill
@@ -2190,153 +2185,163 @@
+
+ position/size
+
+
+
+
+
+
+
+
shadow
-
+
Ellipse object properties
-
+
Image object properties
-
+
image
-
+
Line object properties
-
+
Text object properties
-
+
text
-
+
Barcode object properties
-
+
barcode
-
+
Object properties
-
+
Line
-
+
Fill
-
+
Image files (*.png *.jpg *.jpeg *.gif *.bmp *.pbm *.pgm *.ppm *.xbm *.xpm *.svg)
-
+
All files (*)
-
+
PNG - Portable Network Graphics (*.png)
-
+
BMP - Windows Bitmap (*.bmp)
-
+
GIF - Graphics Interchange Format (*.gif)
-
+
JPEG - Joint Photographic Experts Group (*.jpg *.jpeg)
-
+
PBM - Portable Bitmap (*.pbm)
-
+
PGM - Portable Graymap (*.pgm)
-
+
PPM - Portable Pixmap (*.ppm)
-
+
SVG - Scalable Vector Graphics (*.svg)
-
+
XBM - X11 Bitmap (*.xbm)
-
+
XPM - X11 Pixmap (*.xpm)
-
+
gLabels - Select image file
-
-
+
+
Set image
-
+
Move
-
-
+
+
Size
-
+
Text
-
+
Shadow
@@ -3065,8 +3070,8 @@
glabels::model::ModelTextObject
-
-
+
+
Text
diff --git a/translations/glabels_de_DE.ts b/translations/glabels_de_DE.ts
index f5da691..b2d33bb 100644
--- a/translations/glabels_de_DE.ts
+++ b/translations/glabels_de_DE.ts
@@ -346,235 +346,240 @@
Form
-
+
Text
Text
-
+
Layout
Anordnung
-
+
Alignment:
Ausrichtung:
-
+
Line spacing:
Zeilenabstand:
-
+
Wrap mode:
-
+
Word
-
+
+ Allow printing to shrink text to fit object
+
+
+
+
Font
Schrift
-
+
Family:
Familie:
-
+
Size:
Größe:
-
+
Style:
Stil:
-
-
-
-
-
+
+
+
+
+
Color:
Farbe:
-
+
Editor
Editor
-
+
Barcode
Strichcode
-
+
Style
Stil
-
+
Type:
Typ:
-
+
Show text
Text anzeigen
-
+
Checksum
Prüfsumme
-
+
Barcode data
Barcode-Daten
-
+
Image
Bild
-
+
File
Datei
-
-
+
+
None
Keine
-
+
Anywhere
-
+
Select File...
Datei auswählen …
-
+
or
oder
-
+
Select Merge Field...
Datenfeld auswählen …
-
+
Line/Fill
Linie/Füllung
-
+
Line
Linie
-
-
+
+
Width:
Breite:
-
+
Fill
Füllung
-
+
Position/Size
Position/Größe
-
+
Position
Position
-
+
X:
X:
-
+
Y:
Y:
-
-
+
+
Size
Größe
-
+
Length:
Länge:
-
+
Angle:
Winkel:
-
+
Original size:
Originalgröße:
-
+
Reset
Zurücksetzen
-
+
Lock aspect ratio
Seitenverhältnis beibehalten
-
+
Height:
Höhe:
-
-
+
+
Shadow
Schattierung
-
+
X offset:
X-Position:
-
+
Y offset:
Y-Position:
-
+
Opacity:
Deckkraft:
-
+
Object properties
Objekteigenschaften
@@ -2163,25 +2168,15 @@
Originalgröße
-
+
Box object properties
Eigenschaften des Rechteck-Objekts
-
-
-
-
- line/fill
-
-
-
-
-
- position/size
+ line/fill
@@ -2190,153 +2185,163 @@
+
+ position/size
+
+
+
+
+
+
+
+
shadow
-
+
Ellipse object properties
Eigenschaften des Ellipsenobjekts
-
+
Image object properties
Eigenschaften des Bildobjekts
-
+
image
-
+
Line object properties
Eigenschaften des Linienobjekts
-
+
Text object properties
Eigenschaften des Textobjekts
-
+
text
-
+
Barcode object properties
Eigenschaften des Strichcode-Objekts
-
+
barcode
-
+
Object properties
Objekteigenschaften
-
+
Line
Linie
-
+
Fill
Füllung
-
+
Image files (*.png *.jpg *.jpeg *.gif *.bmp *.pbm *.pgm *.ppm *.xbm *.xpm *.svg)
Bilddateien (*.png *.jpg *.jpeg *.gif *.bmp *.pbm *.pgm *.ppm *.xbm *.xpm *.svg)
-
+
All files (*)
Alle Dateien (*)
-
+
PNG - Portable Network Graphics (*.png)
PNG - Portable Network Graphics (*.png)
-
+
BMP - Windows Bitmap (*.bmp)
BMP - Windows Bitmap (*.bmp)
-
+
GIF - Graphics Interchange Format (*.gif)
GIF - Graphics Interchange Format (*.gif)
-
+
JPEG - Joint Photographic Experts Group (*.jpg *.jpeg)
JPEG - Joint Photographic Experts Group (*.jpg *.jpeg)
-
+
PBM - Portable Bitmap (*.pbm)
PBM - Portable Bitmap (*.pbm)
-
+
PGM - Portable Graymap (*.pgm)
PGM - Portable Graymap (*.pgm)
-
+
PPM - Portable Pixmap (*.ppm)
PPM - Portable Pixmap (*.ppm)
-
+
SVG - Scalable Vector Graphics (*.svg)
SVG - Scalable Vector Graphics (*.svg)
-
+
XBM - X11 Bitmap (*.xbm)
XBM - X11 Bitmap (*.xbm)
-
+
XPM - X11 Pixmap (*.xpm)
XPM - X11 Pixmap (*.xpm)
-
+
gLabels - Select image file
gLabels - Bilddatei wählen
-
-
+
+
Set image
Bild festlegen
-
+
Move
Verschieben
-
-
+
+
Size
Größe
-
+
Text
Text
-
+
Shadow
Schattierung
@@ -3065,8 +3070,8 @@
glabels::model::ModelTextObject
-
-
+
+
Text
Text