49
51
#include "undostate.h"
50
52
#include "scconfig.h"
55
#include "scfontmetrics.h"
56
#include "text/nlsconfig.h"
58
58
using namespace std;
60
60
PageItem_PathText::PageItem_PathText(ScribusDoc *pa, double x, double y, double w, double h, double w2, QString fill, QString outline)
61
61
: PageItem(pa, PageItem::PathText, x, y, w, h, w2, fill, outline)
65
void PageItem_PathText::DrawObj_Item(ScPainter *p, double sc)
64
MaxChars = itemText.length();
68
void PageItem_PathText::layout()
70
QPixmap pgPix(10, 10);
71
QRect rd = QRect(0,0,9,9);
72
ScPainter *painter = new ScPainter(&pgPix, pgPix.width(), pgPix.height());
81
void PageItem_PathText::DrawObj_Item(ScPainter *p, QRect e, double sc)
83
itemText.invalidateAll();
70
QString chx, chx2, chx3;
88
QString chstr, chstr2, chstr3;
85
102
double segLen = 0;
106
QString cachedStroke = "";
107
QString cachedFill = "";
108
int cachedFillShade = -1;
109
int cachedStrokeShade = -1;
110
QString actStroke = "";
111
QString actFill = "";
112
int actFillShade = -1;
113
int actStrokeShade = -1;
115
QColor cachedStrokeQ;
116
if (!m_Doc->layerOutline(LayerNr))
90
if (lineColor() != CommonStrings::None && PoShow)
92
p->setupPolygon(&PoLine, false);
97
if (NamedLStyle.isEmpty())
98
p->drawLine(FPoint(0, 0), FPoint(Width, 0));
120
if (lineColor() != CommonStrings::None && PoShow)
122
p->setupPolygon(&PoLine, false);
101
multiLine ml = m_Doc->MLineStyles[NamedLStyle];
103
for (int it = ml.size()-1; it > -1; it--)
127
if (NamedLStyle.isEmpty())
128
p->drawLine(FPoint(0, 0), FPoint(Width, 0));
105
if ((ml[it].Color != CommonStrings::None) && (ml[it].Width != 0))
131
multiLine ml = m_Doc->MLineStyles[NamedLStyle];
132
for (int it = ml.size()-1; it > -1; it--)
107
SetFarbe(&tmp, ml[it].Color, ml[it].Shade);
108
p->setPen(tmp, ml[it].Width, static_cast<PenStyle>(ml[it].Dash), static_cast<PenCapStyle>(ml[it].LineEnd), static_cast<PenJoinStyle>(ml[it].LineJoin));
109
p->drawLine(FPoint(0, 0), FPoint(Width, 0));
134
if ((ml[it].Color != CommonStrings::None) && (ml[it].Width != 0))
136
SetFarbe(&tmp, ml[it].Color, ml[it].Shade);
137
p->setPen(tmp, ml[it].Width, static_cast<PenStyle>(ml[it].Dash), static_cast<PenCapStyle>(ml[it].LineEnd), static_cast<PenJoinStyle>(ml[it].LineJoin));
138
p->drawLine(FPoint(0, 0), FPoint(Width, 0));
115
if (itemText.count() != 0)
116
CurX += itemText.at(0)->csize * itemText.at(0)->cextra / 10000.0;
145
double totalTextLen = 0.0;
146
double totalCurveLen = 0.0;
147
double extraOffset = 0.0;
148
if (itemText.length() != 0)
150
CurX += itemText.charStyle(0).fontSize() * itemText.charStyle(0).tracking() / 10000.0;
151
totalTextLen += itemText.charStyle(0).fontSize() * itemText.charStyle(0).tracking() / 10000.0;
117
153
segLen = PoLine.lenPathSeg(seg);
118
for (a = 0; a < itemText.count(); ++a)
154
for (a = firstChar; a < itemText.length(); ++a)
156
hl = itemText.item(a);
158
if (chstr[0] == SpecialChars::PAGENUMBER || chstr[0] == SpecialChars::PARSEP
159
|| chstr[0] == SpecialChars::TAB || chstr == SpecialChars::LINEBREAK)
161
if (a < itemText.length()-1)
162
chstr += itemText.text(a+1, 1);
163
hl->glyph.yadvance = 0;
164
layoutGlyphs(itemText.charStyle(a), chstr, hl->glyph);
166
if (hl->ch[0] == SpecialChars::OBJECT)
167
totalTextLen += (hl->embedded.getItem()->gWidth + hl->embedded.getItem()->lineWidth());
169
totalTextLen += hl->glyph.wide()+hl->fontSize() * hl->tracking() / 10000.0;
171
for (uint segs = 0; segs < PoLine.size()-3; segs += 4)
173
totalCurveLen += PoLine.lenPathSeg(segs);
175
if ((itemText.defaultStyle().alignment() != 0) && (totalCurveLen >= totalTextLen + Extra))
177
if (itemText.defaultStyle().alignment() == 2)
179
CurX = totalCurveLen - totalTextLen;
182
if (itemText.defaultStyle().alignment() == 1)
183
CurX = (totalCurveLen - totalTextLen) / 2.0;
184
if ((itemText.defaultStyle().alignment() == 3) || (itemText.defaultStyle().alignment() == 4))
185
extraOffset = (totalCurveLen - Extra - totalTextLen) / static_cast<double>(itemText.length());
188
for (a = firstChar; a < itemText.length(); ++a)
123
if ((chx == QChar(30)) || (chx == QChar(13)) || (chx == QChar(9)) || (chx == QChar(28)))
191
hl = itemText.item(a);
193
if (chstr[0] == SpecialChars::PAGENUMBER || chstr[0] == SpecialChars::PARSEP
194
|| chstr[0] == SpecialChars::TAB || chstr == SpecialChars::LINEBREAK)
126
SetZeichAttr(hl, &chs, &chx);
127
if (chx == QChar(29))
129
else if (chx == QChar(24))
133
if (a < itemText.count()-1)
135
if (itemText.at(a+1)->ch == QChar(29))
137
else if (itemText.at(a+1)->ch == QChar(24))
140
chx3 = itemText.at(a+1)->ch;
141
wide = Cwidth(m_Doc, hl->cfont, chx2, chs, chx3);
144
wide = Cwidth(m_Doc, hl->cfont, chx2, chs);
145
wide = wide * (hl->cscale / 1000.0);
196
chs = hl->fontSize();
197
if (a < itemText.length()-1)
198
chstr += itemText.text(a+1, 1);
199
hl->glyph.yadvance = 0;
200
layoutGlyphs(itemText.charStyle(a), chstr, hl->glyph);
201
hl->glyph.shrink(); // HACK
202
if (hl->ch[0] == SpecialChars::OBJECT)
203
dx = (hl->embedded.getItem()->gWidth + hl->embedded.getItem()->lineWidth()) / 2.0;
205
dx = hl->glyph.wide() / 2.0;
206
// qDebug(QString("pathtext-draw: parent %1 parentc %2").arg((uint)itemText.paragraphStyle(a).parentStyle()).arg((uint)itemText.charStyle(a).parentStyle()));
207
// qDebug(QString("pathtext-draw: co %1 %2 %3 %4").arg(itemText.charStyle(a).fillColor()).arg(itemText.charStyle(a).fillShade()).arg(itemText.charStyle(a).strokeColor()).arg(itemText.charStyle(a).strokeShade()));
208
// qDebug(QString("pathtext-draw: fo %1 %2").arg(itemText.charStyle(a).font().scName()).arg(hl->glyph.glyph));
149
211
while ( (seg < PoLine.size()-3) && (CurX > fsx + segLen))
262
hl->glyph.xoffset = 0;
263
hl->glyph.yoffset = BaseOffs;
202
264
hl->PtransX = tangent.x();
203
265
hl->PtransY = tangent.y();
267
// qDebug(QString("'%1' (%2,%3) %4+%5").arg(itemText.text(a)).arg(point.x()).arg(point.y()).arg(CurX).arg(dx));
269
QWMatrix trafo = QWMatrix( 1, 0, 0, -1, -dx, 0 );
271
trafo *= QWMatrix(1, 0, 0, -1, 0, 0);
272
if (textPathType == 0)
273
trafo *= QWMatrix( tangent.x(), tangent.y(), tangent.y(), -tangent.x(), point.x(), point.y() ); // ID's Rainbow mode
274
else if (textPathType == 1)
275
trafo *= QWMatrix( 1, 0, 0, -1, point.x(), point.y() ); // ID's Stair Step mode
276
else if (textPathType == 2)
281
if (fabs(tangent.x()) > 0.1)
282
trafo *= QWMatrix( a, (tangent.y() / tangent.x()) * a, 0, -1, point.x(), point.y() ); // ID's Skew mode
284
trafo *= QWMatrix( a, 4 * a, 0, -1, point.x(), point.y() );
205
287
QWMatrix trafo = QWMatrix( 1, 0, 0, -1, -dx*sc, 0 );
206
trafo *= QWMatrix( tangent.x(), tangent.y(), tangent.y(), -tangent.x(), point.x()*sc, point.y()*sc );
289
trafo *= QWMatrix(1, 0, 0, -1, 0, 0);
290
if (textPathType == 0)
291
trafo *= QWMatrix( tangent.x(), tangent.y(), tangent.y(), -tangent.x(), point.x()*sc, point.y()*sc ); // ID's Rainbow mode
292
else if (textPathType == 1)
293
trafo *= QWMatrix( 1, 0, 0, -1, point.x()*sc, point.y()*sc ); // ID's Stair Step mode
294
else if (textPathType == 2)
299
if (fabs(tangent.x()) > 0.1)
300
trafo *= QWMatrix( a, (tangent.y() / tangent.x()) * a, 0, -1, point.x()*sc, point.y()*sc ); // ID's Skew mode
302
trafo *= QWMatrix( a, 4 * a, 0, -1, point.x()*sc, point.y()*sc );
207
305
QWMatrix sca = p->worldMatrix();
210
308
QWMatrix savWM = p->worldMatrix();
211
309
p->setWorldMatrix(trafo);
214
if (hl->ccolor != CommonStrings::None)
217
SetFarbe(&tmp, hl->ccolor, hl->cshade);
220
if (hl->cstroke != CommonStrings::None)
223
SetFarbe(&tmp, hl->cstroke, hl->cshade2);
224
p->setPen(tmp, 1, SolidLine, FlatCap, MiterJoin);
226
Zli->Farb = hl->ccolor;
227
Zli->Farb2 = hl->cstroke;
228
Zli->shade = hl->cshade;
229
Zli->shade2 = hl->cshade2;
232
Zli->Sele = hl->cselect;
234
Zli->realSiz = hl->csize;
235
Zli->Style = hl->cstyle;
236
Zli->ZFo = hl->cfont;
238
Zli->kern = hl->csize * hl->cextra / 10000.0;
239
Zli->scale = hl->cscale;
240
Zli->scalev = hl->cscalev;
241
Zli->base = hl->cbase;
242
Zli->shadowX = hl->cshadowx;
243
Zli->shadowY = hl->cshadowx;
244
Zli->outline = hl->coutline;
245
Zli->underpos = hl->cunderpos;
246
Zli->underwidth = hl->cunderwidth;
247
Zli->strikepos = hl->cstrikepos;
248
Zli->strikewidth = hl->cstrikewidth;
250
310
if (!m_Doc->RePos)
251
DrawZeichenS(p, Zli);
312
actFill = itemText.charStyle(a).fillColor();
313
actFillShade = itemText.charStyle(a).fillShade();
314
if (actFill != CommonStrings::None)
316
if ((cachedFillShade != actFillShade) || (cachedFill != actFill))
318
SetFarbe(&tmp, actFill, actFillShade);
321
cachedFill = actFill;
322
cachedFillShade = actFillShade;
325
p->setBrush(cachedFillQ);
327
actStroke = itemText.charStyle(a).strokeColor();
328
actStrokeShade = itemText.charStyle(a).strokeShade();
329
if (actStroke != CommonStrings::None)
331
if ((cachedStrokeShade != actStrokeShade) || (cachedStroke != actStroke))
333
SetFarbe(&tmp, actStroke, actStrokeShade);
334
p->setPen(tmp, 1, SolidLine, FlatCap, MiterJoin);
336
cachedStroke = actStroke;
337
cachedStrokeShade = actStrokeShade;
340
p->setPen(cachedStrokeQ, 1, SolidLine, FlatCap, MiterJoin);
342
if (hl->ch[0] == SpecialChars::OBJECT)
344
p->translate(0.0, BaseOffs);
345
DrawObj_Embedded(p, e, itemText.charStyle(a), hl->embedded.getItem());
348
drawGlyphs(p, itemText.charStyle(a), hl->glyph);
350
hl->glyph.xoffset = point.x();
351
hl->glyph.yoffset = point.y();
253
352
p->setWorldMatrix(savWM);
255
355
p->setZoomFactor(sc);
259
CurX += wide+hl->csize * hl->cextra / 10000.0;
360
if (hl->ch[0] == SpecialChars::OBJECT)
361
CurX += (hl->embedded.getItem()->gWidth + hl->embedded.getItem()->lineWidth());
363
CurX += hl->glyph.wide()+hl->fontSize() * hl->tracking() / 10000.0 + extraOffset;
366
MaxChars++; // ugly Hack
368
// qDebug(QString("PageItem_PathText::DrawObj_Item repos=%1, %2 chars, [%3 %4 %5 %6 %7 %8] with %9").arg(m_Doc->RePos).arg(MaxChars)
369
// .arg(p->worldMatrix().m11()).arg(p->worldMatrix().m12()).arg(p->worldMatrix().m21()).arg(p->worldMatrix().m22()).arg(p->worldMatrix().dx()).arg(p->worldMatrix().dy())
370
// .arg(QString("pen %1 brush%2 device%3 isPainting=%4").arg(p->pen().rgb()).arg(p->brush().rgb()).arg(p->device()? p->device()->paintingActive() : -999))