src/gui/text/qtextlayout.cpp
branchGCC_SURGE
changeset 31 5daf16870df6
parent 30 5dc02b23752f
child 33 3e2da88830cd
equal deleted inserted replaced
27:93b982ccede2 31:5daf16870df6
   303     QTextLayout can be used to create a sequence of QTextLine's with
   303     QTextLayout can be used to create a sequence of QTextLine's with
   304     given widths and can position them independently on the screen.
   304     given widths and can position them independently on the screen.
   305     Once the layout is done, these lines can be drawn on a paint
   305     Once the layout is done, these lines can be drawn on a paint
   306     device.
   306     device.
   307 
   307 
   308     Here's some pseudo code that presents the layout phase:
   308     Here's some code snippet that presents the layout phase:
   309     \snippet doc/src/snippets/code/src_gui_text_qtextlayout.cpp 0
   309     \snippet doc/src/snippets/code/src_gui_text_qtextlayout.cpp 0
   310 
   310 
   311     The text can be drawn by calling the layout's draw() function:
   311     The text can be drawn by calling the layout's draw() function:
   312     \snippet doc/src/snippets/code/src_gui_text_qtextlayout.cpp 1
   312     \snippet doc/src/snippets/code/src_gui_text_qtextlayout.cpp 1
   313 
   313 
  1566     by layout() without changing the line break position.
  1566     by layout() without changing the line break position.
  1567 */
  1567 */
  1568 qreal QTextLine::naturalTextWidth() const
  1568 qreal QTextLine::naturalTextWidth() const
  1569 {
  1569 {
  1570     return eng->lines[i].textWidth.toReal();
  1570     return eng->lines[i].textWidth.toReal();
       
  1571 }
       
  1572 
       
  1573 /*! \since 4.7
       
  1574   Returns the horizontal advance of the text. The advance of the text
       
  1575   is the distance from its position to the next position at which
       
  1576   text would naturally be drawn.
       
  1577 
       
  1578   By adding the advance to the position of the text line and using this
       
  1579   as the position of a second text line, you will be able to position
       
  1580   the two lines side-by-side without gaps in-between.
       
  1581 */
       
  1582 qreal QTextLine::horizontalAdvance() const
       
  1583 {
       
  1584     return eng->lines[i].textAdvance.toReal();
  1571 }
  1585 }
  1572 
  1586 
  1573 /*!
  1587 /*!
  1574     Lays out the line with the given \a width. The line is filled from
  1588     Lays out the line with the given \a width. The line is filled from
  1575     its starting position with as many characters as will fit into
  1589     its starting position with as many characters as will fit into
  1926     LB_DEBUG("reached end of line");
  1940     LB_DEBUG("reached end of line");
  1927     lbh.checkFullOtherwiseExtend(line);
  1941     lbh.checkFullOtherwiseExtend(line);
  1928 found:       
  1942 found:       
  1929     if (lbh.rightBearing > 0) // If right bearing has not yet been adjusted
  1943     if (lbh.rightBearing > 0) // If right bearing has not yet been adjusted
  1930         lbh.adjustRightBearing();
  1944         lbh.adjustRightBearing();
       
  1945     line.textAdvance = line.textWidth;
  1931     line.textWidth -= qMin(QFixed(), lbh.rightBearing);
  1946     line.textWidth -= qMin(QFixed(), lbh.rightBearing);
  1932 
  1947 
  1933     if (line.length == 0) {
  1948     if (line.length == 0) {
  1934         LB_DEBUG("no break available in line, adding temp: length %d, width %f, space: length %d, width %f",
  1949         LB_DEBUG("no break available in line, adding temp: length %d, width %f, space: length %d, width %f",
  1935                lbh.tmpData.length, lbh.tmpData.textWidth.toReal(),
  1950                lbh.tmpData.length, lbh.tmpData.textWidth.toReal(),