~ubuntu-branches/ubuntu/maverick/scribus-ng/maverick-backports

« back to all changes in this revision

Viewing changes to scribus/pageitem_pathtext.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Oleksandr Moskalenko
  • Date: 2007-08-11 17:41:51 UTC
  • mfrom: (0.1.1 upstream) (4.1.2 feisty)
  • Revision ID: james.westby@ubuntu.com-20070811174151-tmkgjvjuc0mtk8ul
Tags: 1.3.4.dfsg+svn20071115-1
* Upstream svn update (Closes: #447480, #448949).
* debian/NEWS: Added a note for users wanting stable Scribus to switch to
  the "scribus" package (Closes: #427638).
* debian/watch: Updated the watch regex to properly track sourceforge
  releases for this branch (Closes: #449700).

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
#include <qfileinfo.h>
32
32
#include <qdrawutil.h>
33
33
#include <qbitmap.h>
 
34
#include <qpixmap.h>
 
35
#include <qrect.h>
34
36
#include <qregexp.h>
35
37
#include <qmessagebox.h>
36
38
#include <cmath>
49
51
#include "undostate.h"
50
52
#include "scconfig.h"
51
53
 
52
 
#include <ft2build.h>
53
 
#include FT_GLYPH_H
54
 
 
55
 
#include "scfontmetrics.h"
56
54
#include "util.h"
57
55
 
 
56
#include "text/nlsconfig.h"
 
57
 
58
58
using namespace std;
59
59
 
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)
62
62
{
63
 
}
64
 
 
65
 
void PageItem_PathText::DrawObj_Item(ScPainter *p, double sc)
66
 
{
67
 
        uint a;
 
63
        firstChar = 0;
 
64
        MaxChars = itemText.length();
 
65
}
 
66
 
 
67
 
 
68
void PageItem_PathText::layout()
 
69
{
 
70
        QPixmap pgPix(10, 10);
 
71
        QRect rd = QRect(0,0,9,9);
 
72
        ScPainter *painter = new ScPainter(&pgPix, pgPix.width(), pgPix.height());      
 
73
        DrawObj(painter, rd);
 
74
        painter->end();
 
75
        delete painter;
 
76
        Frame = true;
 
77
        updatePolyClip();
 
78
}
 
79
 
 
80
 
 
81
void PageItem_PathText::DrawObj_Item(ScPainter *p, QRect e, double sc)
 
82
{
 
83
        itemText.invalidateAll();
 
84
        firstChar = 0;
 
85
        MaxChars = 0;
 
86
        int a;
68
87
        int chs;
69
 
        double wide;
70
 
        QString chx, chx2, chx3;
 
88
        QString chstr, chstr2, chstr3;
71
89
        ScText *hl;
72
 
        struct ZZ *Zli;
73
90
        double dx;
74
91
        double sp = 0;
75
92
        double oldSp = 0;
84
101
        uint seg = 0;
85
102
        double segLen = 0;
86
103
        double distCurX;
 
104
        QColor tmp;
87
105
        CurX = Extra;
88
 
        if (PoShow)
 
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;
 
114
        QColor cachedFillQ;
 
115
        QColor cachedStrokeQ;
 
116
        if (!m_Doc->layerOutline(LayerNr))
89
117
        {
90
 
                if (lineColor() != CommonStrings::None && PoShow)
91
 
                {
92
 
                        p->setupPolygon(&PoLine, false);
93
 
                        p->strokePath();
94
 
                }
95
 
                else
96
 
                {
97
 
                        if (NamedLStyle.isEmpty())
98
 
                                p->drawLine(FPoint(0, 0), FPoint(Width, 0));
 
118
                if (PoShow)
 
119
                {
 
120
                        if (lineColor() != CommonStrings::None && PoShow)
 
121
                        {
 
122
                                p->setupPolygon(&PoLine, false);
 
123
                                p->strokePath();
 
124
                        }
99
125
                        else
100
126
                        {
101
 
                                multiLine ml = m_Doc->MLineStyles[NamedLStyle];
102
 
                                QColor tmp;
103
 
                                for (int it = ml.size()-1; it > -1; it--)
 
127
                                if (NamedLStyle.isEmpty())
 
128
                                        p->drawLine(FPoint(0, 0), FPoint(Width, 0));
 
129
                                else
104
130
                                {
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--)
106
133
                                        {
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))
 
135
                                                {
 
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));
 
139
                                                }
110
140
                                        }
111
141
                                }
112
142
                        }
113
143
                }
114
144
        }
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)
 
149
        {
 
150
                CurX += itemText.charStyle(0).fontSize() * itemText.charStyle(0).tracking() / 10000.0;
 
151
                totalTextLen += itemText.charStyle(0).fontSize() * itemText.charStyle(0).tracking() / 10000.0;
 
152
        }
117
153
        segLen = PoLine.lenPathSeg(seg);
118
 
        for (a = 0; a < itemText.count(); ++a)
 
154
        for (a = firstChar; a < itemText.length(); ++a)
 
155
        {
 
156
                hl = itemText.item(a);
 
157
                chstr = hl->ch;
 
158
                if (chstr[0] == SpecialChars::PAGENUMBER || chstr[0] == SpecialChars::PARSEP
 
159
                        || chstr[0] == SpecialChars::TAB || chstr == SpecialChars::LINEBREAK)
 
160
                        continue;
 
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);
 
165
                hl->glyph.shrink();
 
166
                if (hl->ch[0] == SpecialChars::OBJECT)
 
167
                        totalTextLen += (hl->embedded.getItem()->gWidth + hl->embedded.getItem()->lineWidth());
 
168
                else
 
169
                        totalTextLen += hl->glyph.wide()+hl->fontSize() * hl->tracking() / 10000.0;
 
170
        }
 
171
        for (uint segs = 0; segs < PoLine.size()-3; segs += 4)
 
172
        {
 
173
                totalCurveLen += PoLine.lenPathSeg(segs);
 
174
        }
 
175
        if ((itemText.defaultStyle().alignment() != 0) && (totalCurveLen >= totalTextLen + Extra))
 
176
        {
 
177
                if (itemText.defaultStyle().alignment() == 2)
 
178
                {
 
179
                        CurX = totalCurveLen  - totalTextLen;
 
180
                        CurX -= Extra;
 
181
                }
 
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());
 
186
        }
 
187
#ifndef NLS_PROTO
 
188
        for (a = firstChar; a < itemText.length(); ++a)
119
189
        {
120
190
                CurY = 0;
121
 
                hl = itemText.at(a);
122
 
                chx = hl->ch;
123
 
                if ((chx == QChar(30)) || (chx == QChar(13)) || (chx == QChar(9)) || (chx == QChar(28)))
 
191
                hl = itemText.item(a);
 
192
                chstr = hl->ch;
 
193
                if (chstr[0] == SpecialChars::PAGENUMBER || chstr[0] == SpecialChars::PARSEP
 
194
                        || chstr[0] == SpecialChars::TAB || chstr == SpecialChars::LINEBREAK)
124
195
                        continue;
125
 
                chs = hl->csize;
126
 
                SetZeichAttr(hl, &chs, &chx);
127
 
                if (chx == QChar(29))
128
 
                        chx2 = " ";
129
 
                else if (chx == QChar(24))
130
 
                        chx2 = "-";
131
 
                else
132
 
                        chx2 = chx;
133
 
                if (a < itemText.count()-1)
134
 
                {
135
 
                        if (itemText.at(a+1)->ch == QChar(29))
136
 
                                chx3 = " ";
137
 
                        else if (itemText.at(a+1)->ch == QChar(24))
138
 
                                chx3 = "-";
139
 
                        else
140
 
                                chx3 = itemText.at(a+1)->ch;
141
 
                        wide = Cwidth(m_Doc, hl->cfont, chx2, chs, chx3);
142
 
                }
143
 
                else
144
 
                        wide = Cwidth(m_Doc, hl->cfont, chx2, chs);
145
 
                wide = wide * (hl->cscale / 1000.0);
146
 
                dx = wide / 2.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;
 
204
                else
 
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));
147
209
                CurX += dx;
148
210
                ext = false;
149
211
                while ( (seg < PoLine.size()-3) && (CurX > fsx + segLen))
197
259
                        else
198
260
                                break;
199
261
                }
200
 
                hl->xp = point.x();
201
 
                hl->yp = point.y();
 
262
                hl->glyph.xoffset = 0;
 
263
                hl->glyph.yoffset = BaseOffs;
202
264
                hl->PtransX = tangent.x();
203
265
                hl->PtransY = tangent.y();
204
266
                hl->PRot = dx;
 
267
//              qDebug(QString("'%1' (%2,%3) %4+%5").arg(itemText.text(a)).arg(point.x()).arg(point.y()).arg(CurX).arg(dx));
 
268
#ifdef HAVE_CAIRO
 
269
                QWMatrix trafo = QWMatrix( 1, 0, 0, -1, -dx, 0 );
 
270
                if (textPathFlipped)
 
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)
 
277
                {
 
278
                        double a = 1;
 
279
                        if (tangent.x() < 0)
 
280
                                a = -1;
 
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
 
283
                        else
 
284
                                trafo *= QWMatrix( a, 4 * a, 0, -1, point.x(), point.y() );
 
285
                }
 
286
#else
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 );
 
288
                if (textPathFlipped)
 
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)
 
295
                {
 
296
                        double a = 1;
 
297
                        if (tangent.x() < 0)
 
298
                                a = -1;
 
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
 
301
                        else
 
302
                                trafo *= QWMatrix( a, 4 * a, 0, -1, point.x()*sc, point.y()*sc );
 
303
                }
 
304
#endif
207
305
                QWMatrix sca = p->worldMatrix();
208
306
                trafo *= sca;
209
307
                p->save();
210
308
                QWMatrix savWM = p->worldMatrix();
211
309
                p->setWorldMatrix(trafo);
212
 
                Zli = new ZZ;
213
 
                Zli->Zeich = chx;
214
 
                if (hl->ccolor != CommonStrings::None)
215
 
                {
216
 
                        QColor tmp;
217
 
                        SetFarbe(&tmp, hl->ccolor, hl->cshade);
218
 
                        p->setBrush(tmp);
219
 
                }
220
 
                if (hl->cstroke != CommonStrings::None)
221
 
                {
222
 
                        QColor tmp;
223
 
                        SetFarbe(&tmp, hl->cstroke, hl->cshade2);
224
 
                        p->setPen(tmp, 1, SolidLine, FlatCap, MiterJoin);
225
 
                }
226
 
                Zli->Farb = hl->ccolor;
227
 
                Zli->Farb2 = hl->cstroke;
228
 
                Zli->shade = hl->cshade;
229
 
                Zli->shade2 = hl->cshade2;
230
 
                Zli->xco = 0;
231
 
                Zli->yco = BaseOffs;
232
 
                Zli->Sele = hl->cselect;
233
 
                Zli->Siz = chs;
234
 
                Zli->realSiz = hl->csize;
235
 
                Zli->Style = hl->cstyle;
236
 
                Zli->ZFo = hl->cfont;
237
 
                Zli->wide = wide;
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;
249
 
                Zli->embedded = 0;
250
310
                if (!m_Doc->RePos)
251
 
                        DrawZeichenS(p, Zli);
252
 
                delete Zli;
 
311
                {
 
312
                        actFill = itemText.charStyle(a).fillColor();
 
313
                        actFillShade = itemText.charStyle(a).fillShade();
 
314
                        if (actFill != CommonStrings::None)
 
315
                        {
 
316
                                if ((cachedFillShade != actFillShade) || (cachedFill != actFill))
 
317
                                {
 
318
                                        SetFarbe(&tmp, actFill, actFillShade);
 
319
                                        p->setBrush(tmp);
 
320
                                        cachedFillQ = tmp;
 
321
                                        cachedFill = actFill;
 
322
                                        cachedFillShade = actFillShade;
 
323
                                }
 
324
                                else
 
325
                                        p->setBrush(cachedFillQ);
 
326
                        }
 
327
                        actStroke = itemText.charStyle(a).strokeColor();
 
328
                        actStrokeShade = itemText.charStyle(a).strokeShade();
 
329
                        if (actStroke != CommonStrings::None)
 
330
                        {
 
331
                                if ((cachedStrokeShade != actStrokeShade) || (cachedStroke != actStroke))
 
332
                                {
 
333
                                        SetFarbe(&tmp, actStroke, actStrokeShade);
 
334
                                        p->setPen(tmp, 1, SolidLine, FlatCap, MiterJoin);
 
335
                                        cachedStrokeQ = tmp;
 
336
                                        cachedStroke = actStroke;
 
337
                                        cachedStrokeShade = actStrokeShade;
 
338
                                }
 
339
                                else
 
340
                                        p->setPen(cachedStrokeQ, 1, SolidLine, FlatCap, MiterJoin);
 
341
                        }
 
342
                        if (hl->ch[0] == SpecialChars::OBJECT)
 
343
                        {
 
344
                                p->translate(0.0, BaseOffs);
 
345
                                DrawObj_Embedded(p, e, itemText.charStyle(a), hl->embedded.getItem());
 
346
                        }
 
347
                        else
 
348
                                drawGlyphs(p, itemText.charStyle(a), hl->glyph);
 
349
                }
 
350
                hl->glyph.xoffset = point.x();
 
351
                hl->glyph.yoffset = point.y();
253
352
                p->setWorldMatrix(savWM);
254
353
                p->restore();
 
354
#ifndef HAVE_CAIRO
255
355
                p->setZoomFactor(sc);
 
356
#endif
256
357
                MaxChars = a+1;
257
358
                oCurX = CurX;
258
359
                CurX -= dx;
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());
 
362
                else
 
363
                        CurX += hl->glyph.wide()+hl->fontSize() * hl->tracking() / 10000.0 + extraOffset;
260
364
                first = false;
261
365
        }
 
366
        MaxChars++;  // ugly Hack
 
367
#endif
 
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))
 
371
//                 );
262
372
}