Commit e5e03140 authored by Elvis Stansvik's avatar Elvis Stansvik

Add support for "style:wrap-dynamic-threshold".

parent c5e71722
......@@ -94,7 +94,8 @@ KoShapePrivate::KoShapePrivate(KoShape *shape)
detectCollision(false),
protectContent(false),
textRunAroundSide(KoShape::BiggestRunAroundSide),
textRunAroundDistance(1.0)
textRunAroundDistance(1.0),
textRunAroundThreshold(0.0)
{
connectors[KoConnectionPoint::TopConnectionPoint] = KoConnectionPoint::defaultConnectionPoint(KoConnectionPoint::TopConnectionPoint);
connectors[KoConnectionPoint::RightConnectionPoint] = KoConnectionPoint::defaultConnectionPoint(KoConnectionPoint::RightConnectionPoint);
......@@ -889,6 +890,18 @@ void KoShape::setTextRunAroundDistance(qreal distance)
d->textRunAroundDistance = distance;
}
qreal KoShape::textRunAroundThreshold() const
{
Q_D(const KoShape);
return d->textRunAroundThreshold;
}
void KoShape::setTextRunAroundThreshold(qreal threshold)
{
Q_D(KoShape);
d->textRunAroundThreshold = threshold;
}
void KoShape::setBackground(KoShapeBackground *fill)
{
Q_D(KoShape);
......@@ -1229,6 +1242,7 @@ QString KoShape::saveStyle(KoGenStyle &style, KoShapeSavingContext &context) con
break;
}
style.addProperty("style:wrap", wrap);
style.addPropertyPt("style:wrap-dynamic-threshold", textRunAroundThreshold());
style.addProperty("fo:margin", QString::number(textRunAroundDistance()) + "pt");
return context.mainStyles().insert(style, context.isSet(KoShapeSavingContext::PresentationShape) ? "pr" : "gr");
......@@ -1300,6 +1314,13 @@ void KoShape::loadStyle(const KoXmlElement &element, KoShapeLoadingContext &cont
else if (wrap == "parallel")
setTextRunAroundSide(KoShape::BothRunAroundSide);
}
if (styleStack.hasProperty(KoXmlNS::style, "wrap-dynamic-threshold")) {
QString wrapThreshold = styleStack.property(KoXmlNS::style, "wrap-dynamic-threshold");
if (!wrapThreshold.isEmpty()) {
setTextRunAroundThreshold(KoUnit::parseValue(wrapThreshold));
}
}
}
bool KoShape::loadOdfAttributes(const KoXmlElement &element, KoShapeLoadingContext &context, int attributes)
......
......@@ -391,6 +391,22 @@ public:
*/
void setTextRunAroundDistance(qreal distance);
/**
* Return the threshold above which text should flow around this shape.
* The text will not flow around the shape on a side unless the space available on that side
* is above this threshold. Only used when the text run around side is EnoughRunAroundSide.
* @return threshold the threshold
*/
qreal textRunAroundThreshold() const;
/**
* Set the threshold above which text should flow around this shape.
* The text will not flow around the shape on a side unless the space available on that side
* is above this threshold. Only used when the text run around side is EnoughRunAroundSide.
* @param threshold the new threshold
*/
void setTextRunAroundThreshold(qreal threshold);
/**
* Set the background of the shape.
* A shape background can be a plain color, a gradient, a pattern, be fully transparent
......
......@@ -92,6 +92,8 @@ public:
qreal textRunAroundDistance;
qreal textRunAroundThreshold;
/// Convert connection point position from shape coordinates, taking alignment into account
void convertFromShapeCoordinates(KoConnectionPoint &point, const QSizeF &shapeSize) const;
......
......@@ -27,7 +27,8 @@ KoTextLayoutObstruction::KoTextLayoutObstruction(KoShape *shape, const QTransfor
: m_side(None),
m_polygon(QPolygonF()),
m_line(QRectF()),
m_shape(shape)
m_shape(shape),
m_runAroundThreshold(0)
{
QPainterPath path = shape->outline();
......@@ -51,6 +52,7 @@ KoTextLayoutObstruction::KoTextLayoutObstruction(KoShape *shape, const QTransfor
m_side = Bigger;
} else if (shape->textRunAroundSide() == KoShape::EnoughRunAroundSide) {
m_side = Enough;
m_runAroundThreshold = shape->textRunAroundThreshold();
}
}
......@@ -199,6 +201,11 @@ bool KoTextLayoutObstruction::textOnEnoughSides() const
return m_side == Enough;
}
qreal KoTextLayoutObstruction::runAroundThreshold() const
{
return m_runAroundThreshold;
}
bool KoTextLayoutObstruction::noTextAround() const
{
return m_side == Empty;
......
......@@ -63,6 +63,9 @@ public:
bool noTextAround() const;
// Don't run around unless available space is > than this when m_side == Enough.
qreal runAroundThreshold() const;
static bool compareRectLeft(KoTextLayoutObstruction *o1, KoTextLayoutObstruction *o2);
private:
enum Side { None, Left, Right, Empty, Both, Bigger, Enough };
......@@ -74,6 +77,7 @@ private:
QMultiMap<qreal, QLineF> m_edges; //sorted with y-coord
KoShape *m_shape;
qreal m_distance;
qreal m_runAroundThreshold;
};
#endif
......@@ -172,10 +172,10 @@ void RunAroundHelper::createLineParts()
} else if (obstruction->textOnEnoughSides()) {
QRectF leftRect = obstruction->getLeftLinePart(m_lineRect);
QRectF rightRect = obstruction->getRightLinePart(m_lineRect);
if (leftRect.width() < 100) { // TODO support actual treshold
if (leftRect.width() < obstruction->runAroundThreshold()) {
lineParts.replace(i, QRectF());
}
if (rightRect.width() < 100) { // TODO support actual treshold
if (rightRect.width() < obstruction->runAroundThreshold()) {
lineParts.replace(i + 1, QRectF());
}
} else if (obstruction->textOnBiggerSide()) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment