~ubuntu-branches/ubuntu/trusty/scribus/trusty

« back to all changes in this revision

Viewing changes to scribus/pageitem_textframe.cpp

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2013-05-16 20:34:07 UTC
  • mfrom: (1.1.13) (32.1.2 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130516203407-ztj7ebsivoo41dih
Tags: 1.4.2.dfsg+r18267-1ubuntu2
Avoid qreal/double type clashes on ARM.

Show diffs side-by-side

added added

removed removed

Lines of Context:
147
147
                        for (int a = 0; a < m_Doc->MasterItems.count(); ++a)
148
148
                        {
149
149
                                docItem = m_Doc->MasterItems.at(a);
 
150
                                // #10642 : masterpage items interact only with items placed on same masterpage
 
151
                                if (docItem->OnMasterPage != OnMasterPage)
 
152
                                        continue;
150
153
                                LayerLevItem = m_Doc->layerLevelFromNumber(docItem->LayerNr);
151
154
                                if (((docItem->ItemNr > ItemNr) && (docItem->LayerNr == LayerNr)) || (LayerLevItem > LayerLev && m_Doc->layerFlow(docItem->LayerNr)))
152
155
                                {
239
242
        }
240
243
}
241
244
 
 
245
static void debugLineLayout(const StoryText& itemText, const LineSpec& line)
 
246
{
 
247
        QFile debugFile(QDir::homePath() + "/Desktop/debug_line.csv");
 
248
        debugFile.open(QIODevice::WriteOnly);
 
249
 
 
250
        QTextStream stream(&debugFile);
 
251
        stream.setRealNumberNotation(QTextStream::FixedNotation);
 
252
        stream.setRealNumberPrecision(7);
 
253
 
 
254
        stream << "xoffset"  << "\t";
 
255
        stream << "yoffset"  << "\t";
 
256
        stream << "xadvance" << "\t";
 
257
        stream << "yadvance" << "\t";
 
258
        stream << "scaleH"   << "\t";
 
259
        stream << "scaleV"   << "\t";
 
260
        stream << "\n";
 
261
 
 
262
        for (int zc = line.firstItem; zc < line.lastItem; ++zc)
 
263
        {
 
264
                const ScText* item = itemText.item(zc);
 
265
 
 
266
                stream << item->glyph.xoffset  << "\t";
 
267
                stream << item->glyph.yoffset  << "\t";
 
268
                stream << item->glyph.xadvance << "\t";
 
269
                stream << item->glyph.yadvance << "\t";
 
270
                stream << item->glyph.scaleH   << "\t";
 
271
                stream << item->glyph.scaleV   << "\t";
 
272
                stream << "\n";
 
273
        }
 
274
 
 
275
        debugFile.close();
 
276
}
 
277
 
242
278
static void dumpIt(const ParagraphStyle& pstyle, QString indent = QString("->"))
243
279
{
244
280
        QString db = QString("%6%1/%2 @ %3: %4--%5 linespa%6: %7 align%8")
1001
1037
        double oldCurY, EndX, OFs, wide, kernVal;
1002
1038
        QString chstr;
1003
1039
        ScText *hl;
 
1040
        PageItem_TextFrame* nextFrame;
1004
1041
        ParagraphStyle style;
1005
 
        int /*ParagraphStyle::OpticalMarginType*/ opticalMargins = ParagraphStyle::OM_None;
 
1042
        int opticalMargins = ParagraphStyle::OM_None;
1006
1043
        
1007
1044
        bool outs = false;
1008
1045
        bool goNoRoom = false;
1562
1599
                                double Xpos, Xend;
1563
1600
                                bool done = false;
1564
1601
                                bool newColumn = false;
 
1602
 
 
1603
                                //FIX ME - that should be paragraph style`s properties
 
1604
                                //if set then indent is add to possible line start point (after overflow)
 
1605
                                //if not then indent is calculated from column left edge
 
1606
                                //if you dont agree that adding indent to overflow should be default behaviour 
 
1607
                                //then change it to false
 
1608
                                bool addIndent2overflow = false; // should be addIndent2Overflow = style.addIndent2Overlow();
 
1609
                                bool addFirstIndent2overflow = true; // should be addFirstIndent2Overflow = style.addFirstIndent2Overlow();
 
1610
                                //if first line indent is negative and left indent should not be added to overflow
 
1611
                                //then dont add first line ident either
 
1612
                                if ((style.firstIndent() < 0) && !addIndent2overflow)
 
1613
                                        addFirstIndent2overflow = false;
 
1614
 
1565
1615
                                while (!done)
1566
1616
                                {
1567
 
                                        Xpos = current.xPos;
 
1617
                                        Xpos = current.xPos + (addIndent2overflow ? 0 : current.leftIndent);
1568
1618
                                        Xend = current.xPos + current.leftIndent;
1569
1619
                                        //check if in indent any overflow occurs
1570
1620
                                        while (Xpos <= Xend && Xpos < current.colRight)
1571
1621
                                        {
 
1622
                                                pt.moveTopLeft(QPoint(static_cast<int>(floor(Xpos)),maxYAsc));
1572
1623
                                                if (!regionContainsRect(cl, pt))
1573
1624
                                                {
1574
1625
                                                        Xpos = current.xPos = realEnd = findRealOverflowEnd(cl, pt, current.colRight);
1575
 
                                                        Xend = current.xPos + current.leftIndent;
 
1626
                                                        Xend = current.xPos + (addIndent2overflow ? current.leftIndent : 0);
 
1627
                                                        //for first paragraph`s line - move it back if first line offset should not be add
 
1628
                                                        if ( addFirstIndent2overflow && (a==0 || (a > 0 && (itemText.text(a-1) == SpecialChars::PARSEP))))
 
1629
                                                                Xend += style.firstIndent();
1576
1630
                                                }
1577
1631
                                                else
1578
1632
                                                        Xpos++;
1579
 
                                                pt.moveTopLeft(QPoint(static_cast<int>(floor(Xpos)),maxYAsc));
1580
1633
                                        }
1581
1634
                                        current.xPos = Xend;
1582
1635
                                        done = true;
1583
 
                                        if (current.isEndOfLine((style.minGlyphExtension() * wide) + current.rightMargin + current.leftIndent))
 
1636
                                        if (current.isEndOfLine((style.minGlyphExtension() * wide) + current.rightMargin))
1584
1637
                                        {
1585
1638
                                                // new line
1586
1639
                                                current.xPos = qMax(current.colLeft, maxDX);
2445
2498
        }
2446
2499
        MaxChars = itemText.length();
2447
2500
        invalid = false;
2448
 
        if (NextBox != NULL) 
 
2501
 
 
2502
        nextFrame = dynamic_cast<PageItem_TextFrame*>(NextBox);
 
2503
        while (nextFrame != NULL)
2449
2504
        {
2450
 
                PageItem_TextFrame* nextFrame = dynamic_cast<PageItem_TextFrame*>(NextBox);
2451
 
                if (nextFrame != NULL)
2452
 
                {
2453
 
                        nextFrame->invalid = true;
2454
 
                        nextFrame->firstChar = MaxChars;
2455
 
                }
 
2505
                nextFrame->invalid   = true;
 
2506
                nextFrame->firstChar = MaxChars;
 
2507
                nextFrame = dynamic_cast<PageItem_TextFrame*>(nextFrame->NextBox);
2456
2508
        }
2457
2509
//      qDebug("textframe: len=%d, done relayout", itemText.length());
2458
2510
        return;
2514
2566
                return;
2515
2567
        QMatrix pf2;
2516
2568
        QPoint pt1, pt2;
2517
 
        double wide, lineCorr;
2518
 
        QChar chstr0;
 
2569
        double wide;
2519
2570
        QString cachedStroke = "";
2520
2571
        QString cachedFill = "";
2521
2572
        double cachedFillShade = -1;
2527
2578
        QColor cachedFillQ;
2528
2579
        QColor cachedStrokeQ;
2529
2580
        //      QValueList<ParagraphStyle::TabRecord> tTabValues;
2530
 
        double desc, asce, tabDist;
 
2581
        double desc, asce;
2531
2582
        //      tTabValues.clear();
2532
2583
        p->save(); //SA1
2533
2584
        //      QRect e2;
2551
2602
                        p->fillPath();
2552
2603
                }
2553
2604
        }
2554
 
        if (lineColor() != CommonStrings::None)
2555
 
                lineCorr = m_lineWidth / 2.0;
2556
 
        else
2557
 
                lineCorr = 0;
2558
2605
        if ((isAnnotation()) && (annotation().Type() == 2) && (!Pfile.isEmpty()) && (PictureIsAvailable) && (PicArt) && (annotation().UseIcons()))
2559
2606
        {
2560
2607
                p->save();//SA2
2614
2661
                        pf2.translate(0, Height);
2615
2662
                        pf2.scale(1, -1);
2616
2663
                }
2617
 
                uint tabCc = 0;
2618
2664
                assert( firstInFrame() >= 0 );
2619
2665
                assert( lastInFrame() < itemText.length() );
2620
2666
                LineSpec ls;
2621
2667
                for (uint ll=0; ll < itemText.lines(); ++ll)
2622
2668
                {
2623
2669
                        ls = itemText.line(ll);
2624
 
                        tabDist = ls.x;
2625
2670
                        double CurX = ls.x;
2626
2671
 
2627
2672
                        // Draw text selection rectangles
2702
2747
                        {
2703
2748
                                hl = itemText.item(a);
2704
2749
                                const CharStyle& charStyle(itemText.charStyle(a));
2705
 
                                double chs = charStyle.fontSize() * hl->glyph.scaleV;
2706
2750
                                bool selected = itemText.selected(a);
2707
 
                                if (charStyle.effects() & ScStyle_StartOfLine)
2708
 
                                        tabCc = 0;
2709
 
                                chstr0 = hl->ch;
 
2751
 
2710
2752
                                actFill = charStyle.fillColor();
2711
2753
                                actFillShade = charStyle.fillShade();
2712
2754
                                if (actFill != CommonStrings::None)
2725
2767
                                }
2726
2768
                                else
2727
2769
                                        p->setFillMode(ScPainter::None);
2728
 
                                if (charStyle.effects() & ScStyle_DropCap)
2729
 
                                {
2730
 
                                        const ParagraphStyle& style(itemText.paragraphStyle(a));
2731
 
                                        if (style.lineSpacingMode() == ParagraphStyle::BaselineGridLineSpacing)
2732
 
                                                chs = qRound(10 * ((m_Doc->typographicSettings.valueBaseGrid * (style.dropCapLines()-1) + (charStyle.font().ascent(style.charStyle().fontSize() / 10.0))) / charStyle.font().realCharHeight(chstr0, 10)));
2733
 
                                        else
2734
 
                                        {
2735
 
                                                if (style.lineSpacingMode() == ParagraphStyle::FixedLineSpacing)
2736
 
                                                        chs = qRound(10 * ((style.lineSpacing() * (style.dropCapLines()-1)+(charStyle.font().ascent(style.charStyle().fontSize() / 10.0))) / charStyle.font().realCharHeight(chstr0, 10)));
2737
 
                                                else
2738
 
                                                {
2739
 
                                                        double currasce = charStyle.font().height(style.charStyle().fontSize() / 10.0);
2740
 
                                                        chs = qRound(10 * ((currasce * (style.dropCapLines()-1)+(charStyle.font().ascent(style.charStyle().fontSize() / 10.0))) / charStyle.font().realCharHeight(chstr0, 10)));
2741
 
                                                }
2742
 
                                        }
2743
 
                                }
2744
 
                                if (chstr0 == SpecialChars::TAB)
2745
 
                                        tabCc++;
2746
2770
 
2747
2771
                                if (!m_Doc->RePos)
2748
2772
                                {
2785
2809
                                        else
2786
2810
                                                CurX += hl->glyph.wide();
2787
2811
                                }
2788
 
                                tabDist = CurX;
2789
2812
                        }
2790
2813
                }
2791
2814
        //      else {
2851
2874
        if ((!isEmbedded) && (!m_Doc->RePos))
2852
2875
        {
2853
2876
                // added to prevent fat frame outline due to antialiasing and considering you can’t pass a cosmetic pen to scpainter - pm
2854
 
                double aestheticFactor(5.0);
2855
 
                double scpInv = 1.0 / (qMax(view->scale(), 1.0) * aestheticFactor);
 
2877
                double aestheticFactor(3.33);
 
2878
                double scpInv = 1.0 / (view->scale() * aestheticFactor);
2856
2879
                if ((Frame) && (m_Doc->guidesSettings.framesShown))
2857
2880
                {
2858
2881
                        p->setPen(PrefsManager::instance()->appPrefs.DFrameNormColor, scpInv, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
2902
2925
                        drawColumnBorders(p);
2903
2926
                if ((m_Doc->guidesSettings.layerMarkersShown) && (m_Doc->layerCount() > 1) && (!m_Doc->layerOutline(LayerNr)) && (!view->m_canvas->isPreviewMode()))
2904
2927
                {
2905
 
                        p->setPen(Qt::black, 0.5/ m_Doc->view()->scale(), Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
 
2928
                        p->setPen(Qt::black, 0.5 / m_Doc->view()->scale(), Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
2906
2929
                        p->setPenOpacity(1.0);
2907
2930
                        p->setBrush(m_Doc->layerMarker(LayerNr));
2908
2931
                        p->setBrushOpacity(1.0);
2974
2997
        }
2975
2998
        int oldPos = itemText.cursorPosition(); // 15-mar-2004 jjsa for cursor movement with Shift + Arrow key
2976
2999
        int kk = k->key();
2977
 
        int as = k->text()[0].unicode();
2978
3000
        QString uc = k->text();
 
3001
#ifdef Q_OS_HAIKU
 
3002
        if (kk == Qt::Key_Return)
 
3003
                uc = "\r";
 
3004
#endif
 
3005
        int as = uc[0].unicode();
2979
3006
        QString cr, Tcha, Twort;
2980
3007
        uint Tcoun;
2981
3008
        int len, pos;
2991
3018
        //<< ISO 14755
2992
3019
        //Check if we are trying to enter Unicode sequence mode first
2993
3020
        QKeySequence currKeySeq = QKeySequence(k->key() | keyModifiers);
2994
 
        if(currKeySeq.matches(doc()->scMW()->scrActions["specialUnicodeSequenceBegin"]->shortcut())==QKeySequence::ExactMatch)
 
3021
        if (currKeySeq.matches(doc()->scMW()->scrActions["specialUnicodeSequenceBegin"]->shortcut())==QKeySequence::ExactMatch)
2995
3022
        {
2996
3023
                unicodeTextEditMode = true;
2997
3024
                unicodeInputCount = 0;
3110
3137
        case Qt::Key_End:
3111
3138
                // go to end of line
3112
3139
                len = lastInFrame();
3113
 
                if ( itemText.cursorPosition() >= len )
 
3140
                if (itemText.cursorPosition() >= (len + 1))
3114
3141
                        break; // at end of frame
3115
 
                if ( (buttonModifiers & Qt::ControlModifier) == 0 )
 
3142
                if ((buttonModifiers & Qt::ControlModifier) == 0)
3116
3143
                {
3117
3144
                        itemText.setCursorPosition( itemText.endOfLine(itemText.cursorPosition()) );
3118
3145
                }
3121
3148
                        //Control End for end of frame text
3122
3149
                        itemText.setCursorPosition( itemText.endOfFrame(itemText.cursorPosition()) );
3123
3150
                }
3124
 
                if ( buttonModifiers & Qt::ShiftModifier )
 
3151
                if (buttonModifiers & Qt::ShiftModifier)
3125
3152
                        ExpandSel(1, oldPos);
3126
 
//              if ( this->itemText.lengthOfSelection() > 0 )
 
3153
//              if (this->itemText.lengthOfSelection() > 0)
3127
3154
//                      view->RefreshItem(this);
3128
3155
                m_Doc->scMW()->setTBvals(this);
3129
3156
                break;
3182
3209
                                break; // at begin of frame
3183
3210
                        len = itemText.length();
3184
3211
                        itemText.setCursorPosition( itemText.prevParagraph(itemText.cursorPosition()) );
3185
 
                        if ( buttonModifiers & Qt::ShiftModifier )
 
3212
                        if (buttonModifiers & Qt::ShiftModifier)
3186
3213
                                ExpandSel(-1, oldPos);
3187
3214
                }
3188
3215
                else
3802
3829
                p->drawLine(FPoint(0, TExtra + lineCorr), FPoint(Width, TExtra + lineCorr));
3803
3830
        if (BExtra + lineCorr!=0.0)
3804
3831
                p->drawLine(FPoint(0, Height - BExtra - lineCorr), FPoint(Width, Height - BExtra - lineCorr));
3805
 
        double oldColRightX = Extra + lineCorr;
3806
3832
        while(curCol < Cols)
3807
3833
        {
3808
3834
                colLeft=(colWidth + ColGap) * curCol + Extra + lineCorr;
3810
3836
                        p->drawLine(FPoint(colLeft, 0), FPoint(colLeft, 0+Height));
3811
3837
                if (colLeft + colWidth != Width)
3812
3838
                        p->drawLine(FPoint(colLeft+colWidth, 0), FPoint(colLeft+colWidth, 0+Height));
3813
 
                oldColRightX=colLeft+colWidth;
3814
3839
                ++curCol;
3815
3840
        }
3816
3841