~ubuntu-branches/debian/sid/librecad/sid

« back to all changes in this revision

Viewing changes to src/lib/engine/rs_text.cpp

  • Committer: Package Import Robot
  • Author(s): Scott Howard
  • Date: 2011-12-17 20:08:57 UTC
  • mfrom: (0.2.4)
  • Revision ID: package-import@ubuntu.com-20111217200857-r9wmynaloj230qm1
Tags: 1.0.0+nolibs-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
**
8
8
**
9
9
** This file may be distributed and/or modified under the terms of the
10
 
** GNU General Public License version 2 as published by the Free Software 
 
10
** GNU General Public License version 2 as published by the Free Software
11
11
** Foundation and appearing in the file gpl-2.0.txt included in the
12
12
** packaging of this file.
13
13
**
15
15
** but WITHOUT ANY WARRANTY; without even the implied warranty of
16
16
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
17
** GNU General Public License for more details.
18
 
** 
 
18
**
19
19
** You should have received a copy of the GNU General Public License
20
20
** along with this program; if not, write to the Free Software
21
21
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22
22
**
23
 
** This copyright notice MUST APPEAR in all copies of the script!  
 
23
** This copyright notice MUST APPEAR in all copies of the script!
24
24
**
25
25
**********************************************************************/
26
26
 
46
46
 
47
47
 
48
48
/**
49
 
 * Sets a new text. The entities representing the 
 
49
 * Sets a new text. The entities representing the
50
50
 * text are updated.
51
51
 */
52
52
void RS_Text::setText(const QString& t) {
146
146
 
147
147
 
148
148
/**
149
 
 * @return Number of lines in this text entity. 
 
149
 * @return Number of lines in this text entity.
150
150
 */
151
151
int RS_Text::getNumberOfLines() {
152
152
    int c=1;
164
164
 
165
165
 
166
166
/**
167
 
 * Updates the Inserts (letters) of this text. Called when the 
 
167
 * Updates the Inserts (letters) of this text. Called when the
168
168
 * text or it's data, position, alignment, .. changes.
169
169
 * This method also updates the usedTextWidth / usedTextHeight property.
170
170
 */
240
240
                        // get upper string:
241
241
                        i++;
242
242
                        while (data.text.at(i).unicode()!='^' &&
243
 
                                                       //data.text.at(i).unicode()!='/' &&
244
 
                                                       data.text.at(i).unicode()!='\\' &&
245
 
                                                       //data.text.at(i).unicode()!='#' &&
 
243
                                                       //data.text.at(i).unicode()!='/' &&
 
244
                                                       data.text.at(i).unicode()!='\\' &&
 
245
                                                       //data.text.at(i).unicode()!='#' &&
246
246
                                i<(int)data.text.length()) {
247
247
                            up += data.text.at(i);
248
248
                            i++;
249
249
                        }
250
 
                                                
 
250
 
251
251
                        i++;
252
 
                                                
253
 
                                                if (data.text.at(i-1).unicode()=='^' &&
254
 
                                                     data.text.at(i).unicode()==' ') {
255
 
                                                        i++;
256
 
                                                }
257
 
                                                
 
252
 
 
253
                                                if (data.text.at(i-1).unicode()=='^' &&
 
254
                                                     data.text.at(i).unicode()==' ') {
 
255
                                                        i++;
 
256
                                                }
 
257
 
258
258
                        // get lower string:
259
259
                        while (data.text.at(i).unicode()!=';' &&
260
260
                                i<(int)data.text.length()) {
267
267
                            new RS_Text(
268
268
                                oneLine,
269
269
                                RS_TextData(letterPos + RS_Vector(0.0,9.0),
270
 
                                            4.0, 100.0, RS2::VAlignTop, 
271
 
                                                                                        RS2::HAlignLeft,
 
270
                                            4.0, 100.0, RS2::VAlignTop,
 
271
                                                                                        RS2::HAlignLeft,
272
272
                                            RS2::LeftToRight, RS2::Exact,
273
273
                                            1.0, up, data.style,
274
274
                                            0.0, RS2::Update));
275
 
                                                upper->setLayer(NULL);
276
 
                        upper->setPen(RS_Pen(RS2::FlagInvalid));
277
 
                                                oneLine->addEntity(upper);
 
275
                                                upper->setLayer(NULL);
 
276
                        upper->setPen(RS_Pen(RS2::FlagInvalid));
 
277
                                                oneLine->addEntity(upper);
278
278
 
279
279
                        RS_Text* lower =
280
280
                            new RS_Text(
281
281
                                oneLine,
282
282
                                RS_TextData(letterPos+RS_Vector(0.0,4.0),
283
 
                                            4.0, 100.0, RS2::VAlignTop, 
284
 
                                                                                        RS2::HAlignLeft,
 
283
                                            4.0, 100.0, RS2::VAlignTop,
 
284
                                                                                        RS2::HAlignLeft,
285
285
                                            RS2::LeftToRight, RS2::Exact,
286
286
                                            1.0, dw, data.style,
287
287
                                            0.0, RS2::Update));
288
 
                                                lower->setLayer(NULL);
289
 
                        lower->setPen(RS_Pen(RS2::FlagInvalid));
 
288
                                                lower->setLayer(NULL);
 
289
                        lower->setPen(RS_Pen(RS2::FlagInvalid));
290
290
                        oneLine->addEntity(lower);
291
291
 
292
292
                        // move cursor:
318
318
        default: {
319
319
                // One Letter:
320
320
                if (font->findLetter(QString(data.text.at(i))) != NULL) {
321
 
                                
322
 
                                        RS_DEBUG->print("RS_Text::update: insert a "
323
 
                                          "letter at pos: %f/%f", letterPos.x, letterPos.y);
 
321
 
 
322
                                        RS_DEBUG->print("RS_Text::update: insert a "
 
323
                                          "letter at pos: %f/%f", letterPos.x, letterPos.y);
324
324
 
325
325
                    RS_InsertData d(QString(data.text.at(i)),
326
326
                                    letterPos,
328
328
                                    0.0,
329
329
                                    1,1, RS_Vector(0.0,0.0),
330
330
                                    font->getLetterList(), RS2::NoUpdate);
331
 
                                        
 
331
 
332
332
                    RS_Insert* letter = new RS_Insert(this, d);
333
333
                    RS_Vector letterWidth;
334
334
                    letter->setPen(RS_Pen(RS2::FlagInvalid));
335
335
                    letter->setLayer(NULL);
336
336
                    letter->update();
337
337
                    letter->forcedCalculateBorders();
338
 
                                        
339
 
                                        // until 2.0.4.5:
 
338
 
 
339
                                        // until 2.0.4.5:
340
340
                    //letterWidth = RS_Vector(letter->getSize().x, 0.0);
341
 
                                        // from 2.0.4.6:
 
341
                                        // from 2.0.4.6:
342
342
                    letterWidth = RS_Vector(letter->getMax().x-letterPos.x, 0.0);
343
343
                    if (letterWidth.x < 0)
344
344
                        letterWidth.x = -letterSpace.x;
348
348
                    // next letter position:
349
349
                    letterPos += letterWidth;
350
350
                    letterPos += letterSpace;
 
351
                }else{
 
352
                    RS_DEBUG->print(RS_Debug::D_WARNING, "RS_Text::update: missing font for letter( %s )",qPrintable(QString(data.text.at(i))));
351
353
                }
352
354
            }
353
355
            break;
358
360
    usedTextHeight -= data.height*data.lineSpacingFactor*1.6
359
361
                      - data.height;
360
362
    forcedCalculateBorders();
361
 
        
 
363
 
362
364
    RS_DEBUG->print("RS_Text::update: OK");
363
365
}
364
366
 
365
367
 
366
368
 
367
369
/**
368
 
 * Used internally by update() to add a text line created with 
 
370
 * Used internally by update() to add a text line created with
369
371
 * default values and alignment to this text container.
370
372
 *
371
373
 * @param textLine The text line.
374
376
void RS_Text::updateAddLine(RS_EntityContainer* textLine, int lineCounter) {
375
377
    RS_DEBUG->print("RS_Text::updateAddLine: width: %f", textLine->getSize().x);
376
378
 
377
 
        //textLine->forcedCalculateBorders();
 
379
        //textLine->forcedCalculateBorders();
378
380
    //RS_DEBUG->print("RS_Text::updateAddLine: width 2: %f", textLine->getSize().x);
379
381
 
380
382
    // Move to correct line position:
381
383
    textLine->move(RS_Vector(0.0, -9.0 * lineCounter
382
384
                             * data.lineSpacingFactor * 1.6));
383
385
 
384
 
        textLine->forcedCalculateBorders();
385
 
        RS_Vector textSize = textLine->getSize();
386
 
    
387
 
        RS_DEBUG->print("RS_Text::updateAddLine: width 2: %f", textSize.x);
 
386
        textLine->forcedCalculateBorders();
 
387
        RS_Vector textSize = textLine->getSize();
 
388
 
 
389
        RS_DEBUG->print("RS_Text::updateAddLine: width 2: %f", textSize.x);
388
390
 
389
391
    // Horizontal Align:
390
392
    switch (data.halign) {
391
393
    case RS2::HAlignCenter:
392
 
                RS_DEBUG->print("RS_Text::updateAddLine: move by: %f", -textSize.x/2.0);
 
394
                RS_DEBUG->print("RS_Text::updateAddLine: move by: %f", -textSize.x/2.0);
393
395
        textLine->move(RS_Vector(-textSize.x/2.0, 0.0));
394
396
        break;
395
397
 
446
448
 
447
449
 
448
450
RS_VectorSolutions RS_Text::getRefPoints() {
449
 
        RS_VectorSolutions ret(data.insertionPoint);
450
 
        return ret;
 
451
        RS_VectorSolutions ret(data.insertionPoint);
 
452
        return ret;
451
453
}
452
 
    
453
 
        
 
454
 
 
455
 
454
456
RS_Vector RS_Text::getNearestRef(const RS_Vector& coord,
455
457
                                     double* dist) {
456
458
 
457
 
        //return getRefPoints().getClosest(coord, dist);
458
 
        return RS_Entity::getNearestRef(coord, dist);
 
459
        //return getRefPoints().getClosest(coord, dist);
 
460
        return RS_Entity::getNearestRef(coord, dist);
459
461
}
460
462
 
461
463
 
521
523
 
522
524
 
523
525
/**
524
 
 * Implementations must stretch the given range of the entity 
 
526
 * Implementations must stretch the given range of the entity
525
527
 * by the given offset.
526
528
 */
527
529
void RS_Text::stretch(RS_Vector firstCorner,