Changeset 769 for trunk/src/gui/text/qtextlayout.cpp
- Timestamp:
- Aug 2, 2010, 9:27:30 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.6.3 (added) merged: 768 /branches/vendor/nokia/qt/current merged: 767 /branches/vendor/nokia/qt/4.6.2 removed
- Property svn:mergeinfo changed
-
trunk/src/gui/text/qtextlayout.cpp
r651 r769 90 90 align = Qt::AlignRight; 91 91 if (align & Qt::AlignRight) 92 x = line.width - (line.text Width+ leadingSpaceWidth(eng, line));92 x = line.width - (line.textAdvance + leadingSpaceWidth(eng, line)); 93 93 else if (align & Qt::AlignHCenter) 94 x = (line.width - line.text Width)/2;94 x = (line.width - line.textAdvance)/2; 95 95 } 96 96 return x; … … 1332 1332 const QScriptLine &sl = d->lines[line]; 1333 1333 1334 constqreal x = position.x() + l.cursorToX(cursorPosition);1334 qreal x = position.x() + l.cursorToX(cursorPosition); 1335 1335 1336 1336 int itm = d->findItem(cursorPosition - 1); … … 1351 1351 if (toggleAntialiasing) 1352 1352 p->setRenderHint(QPainter::Antialiasing); 1353 #if defined(QT_MAC_USE_COCOA) 1354 // Always draw the cursor aligned to pixel boundary. 1355 x = qRound(x); 1356 #endif 1353 1357 p->fillRect(QRectF(x, y, qreal(width), (base + descent + 1).toReal()), p->pen().brush()); 1354 1358 if (toggleAntialiasing) … … 1641 1645 struct LineBreakHelper 1642 1646 { 1643 LineBreakHelper() : glyphCount(0), maxGlyphs(0), manualWrap(false) {} 1647 LineBreakHelper() 1648 : glyphCount(0), maxGlyphs(0), currentPosition(0), fontEngine(0), logClusters(0), 1649 manualWrap(false) 1650 { 1651 } 1652 1644 1653 1645 1654 QScriptLine tmpData; 1646 1655 QScriptLine spaceData; 1647 1656 1657 QGlyphLayout glyphs; 1658 1648 1659 int glyphCount; 1649 1660 int maxGlyphs; 1661 int currentPosition; 1650 1662 1651 1663 QFixed minw; 1652 1664 QFixed softHyphenWidth; 1653 1665 QFixed rightBearing; 1666 QFixed minimumRightBearing; 1667 1668 QFontEngine *fontEngine; 1669 const unsigned short *logClusters; 1654 1670 1655 1671 bool manualWrap; 1656 1672 1657 1673 bool checkFullOtherwiseExtend(QScriptLine &line); 1674 1675 QFixed calculateNewWidth(const QScriptLine &line) const { 1676 return line.textWidth + tmpData.textWidth + spaceData.textWidth + softHyphenWidth 1677 - qMin(rightBearing, QFixed()); 1678 } 1679 1680 inline glyph_t currentGlyph() const 1681 { 1682 Q_ASSERT(currentPosition > 0); 1683 return glyphs.glyphs[logClusters[currentPosition - 1]]; 1684 } 1685 1686 inline void adjustRightBearing() 1687 { 1688 if (currentPosition <= 0) 1689 return; 1690 1691 qreal rb; 1692 fontEngine->getGlyphBearings(currentGlyph(), 0, &rb); 1693 rightBearing = qMin(QFixed(), QFixed::fromReal(rb)); 1694 } 1695 1696 inline void resetRightBearing() 1697 { 1698 rightBearing = QFixed(1); // Any positive number is defined as invalid since only 1699 // negative right bearings are interesting to us. 1700 } 1658 1701 }; 1659 1702 … … 1662 1705 LB_DEBUG("possible break width %f, spacew=%f", tmpData.textWidth.toReal(), spaceData.textWidth.toReal()); 1663 1706 1664 QFixed newWidth = line.textWidth + tmpData.textWidth + spaceData.textWidth + softHyphenWidth + rightBearing;1707 QFixed newWidth = calculateNewWidth(line); 1665 1708 if (line.length && !manualWrap && (newWidth > line.width || glyphCount > maxGlyphs)) 1666 1709 return true; … … 1738 1781 1739 1782 const HB_CharAttributes *attributes = eng->attributes(); 1740 int pos= line.from;1783 lbh.currentPosition = line.from; 1741 1784 int end = 0; 1742 QGlyphLayout glyphs; 1743 const unsigned short *logClusters = eng->layoutData->logClustersPtr; 1785 lbh.logClusters = eng->layoutData->logClustersPtr; 1744 1786 1745 1787 while (newItem < eng->layoutData->items.size()) { 1746 lbh.r ightBearing = 0;1788 lbh.resetRightBearing(); 1747 1789 lbh.softHyphenWidth = 0; 1748 1790 if (newItem != item) { … … 1752 1794 eng->shape(item); 1753 1795 attributes = eng->attributes(); 1754 l ogClusters = eng->layoutData->logClustersPtr;1796 lbh.logClusters = eng->layoutData->logClustersPtr; 1755 1797 } 1756 pos= qMax(line.from, current.position);1798 lbh.currentPosition = qMax(line.from, current.position); 1757 1799 end = current.position + eng->length(item); 1758 glyphs = eng->shapedGlyphs(¤t);1800 lbh.glyphs = eng->shapedGlyphs(¤t); 1759 1801 } 1760 1802 const QScriptItem ¤t = eng->layoutData->items[item]; 1803 QFontEngine *fontEngine = eng->fontEngine(current); 1804 if (lbh.fontEngine != fontEngine) { 1805 lbh.fontEngine = fontEngine; 1806 lbh.minimumRightBearing = qMin(QFixed(), 1807 QFixed::fromReal(fontEngine->minRightBearing())); 1808 } 1761 1809 1762 1810 lbh.tmpData.leading = qMax(lbh.tmpData.leading + lbh.tmpData.ascent, … … 1788 1836 line.setDefaultHeight(eng); 1789 1837 if (eng->option.flags() & QTextOption::ShowLineAndParagraphSeparators) { 1790 addNextCluster( pos, end, lbh.tmpData, lbh.glyphCount,1791 current, l ogClusters,glyphs);1838 addNextCluster(lbh.currentPosition, end, lbh.tmpData, lbh.glyphCount, 1839 current, lbh.logClusters, lbh.glyphs); 1792 1840 } else { 1793 1841 lbh.tmpData.length++; … … 1808 1856 if (lbh.checkFullOtherwiseExtend(line)) 1809 1857 goto found; 1810 } else if (attributes[ pos].whiteSpace) {1811 while ( pos < end && attributes[pos].whiteSpace)1812 addNextCluster( pos, end, lbh.spaceData, lbh.glyphCount,1813 current, l ogClusters,glyphs);1858 } else if (attributes[lbh.currentPosition].whiteSpace) { 1859 while (lbh.currentPosition < end && attributes[lbh.currentPosition].whiteSpace) 1860 addNextCluster(lbh.currentPosition, end, lbh.spaceData, lbh.glyphCount, 1861 current, lbh.logClusters, lbh.glyphs); 1814 1862 1815 1863 if (!lbh.manualWrap && lbh.spaceData.textWidth > line.width) { … … 1820 1868 bool sb_or_ws = false; 1821 1869 do { 1822 addNextCluster( pos, end, lbh.tmpData, lbh.glyphCount,1823 current, l ogClusters,glyphs);1824 1825 if (attributes[ pos].whiteSpace || attributes[pos-1].lineBreakType != HB_NoBreak) {1870 addNextCluster(lbh.currentPosition, end, lbh.tmpData, lbh.glyphCount, 1871 current, lbh.logClusters, lbh.glyphs); 1872 1873 if (attributes[lbh.currentPosition].whiteSpace || attributes[lbh.currentPosition-1].lineBreakType != HB_NoBreak) { 1826 1874 sb_or_ws = true; 1827 1875 break; 1828 } else if (breakany && attributes[ pos].charStop) {1876 } else if (breakany && attributes[lbh.currentPosition].charStop) { 1829 1877 break; 1830 1878 } 1831 } while ( pos< end);1879 } while (lbh.currentPosition < end); 1832 1880 lbh.minw = qMax(lbh.tmpData.textWidth, lbh.minw); 1833 1881 1834 if ( pos && attributes[pos- 1].lineBreakType == HB_SoftHyphen) {1882 if (lbh.currentPosition && attributes[lbh.currentPosition - 1].lineBreakType == HB_SoftHyphen) { 1835 1883 // if we are splitting up a word because of 1836 1884 // a soft hyphen then we ... … … 1850 1898 // 1851 1899 if (line.length) 1852 lbh.softHyphenWidth = glyphs.advances_x[logClusters[pos- 1]];1900 lbh.softHyphenWidth = lbh.glyphs.advances_x[lbh.logClusters[lbh.currentPosition - 1]]; 1853 1901 else if (breakany) 1854 lbh.tmpData.textWidth += glyphs.advances_x[logClusters[pos- 1]];1902 lbh.tmpData.textWidth += lbh.glyphs.advances_x[lbh.logClusters[lbh.currentPosition - 1]]; 1855 1903 } 1856 1904 … … 1859 1907 // of the advance of the glyph, the bearing will be negative. We flip the sign 1860 1908 // for the code to be more readable. Logic borrowed from qfontmetrics.cpp. 1861 if (pos) { 1862 QFontEngine *fontEngine = eng->fontEngine(current); 1863 glyph_t glyph = glyphs.glyphs[logClusters[pos - 1]]; 1864 glyph_metrics_t gi = fontEngine->boundingBox(glyph); 1865 if (gi.isValid()) 1866 lbh.rightBearing = qMax(QFixed(), -(gi.xoff - gi.x - gi.width)); 1909 // We ignore the right bearing if the minimum negative bearing is too little to 1910 // expand the text beyond the edge. 1911 if (sb_or_ws|breakany) { 1912 if (lbh.calculateNewWidth(line) + lbh.minimumRightBearing > line.width) 1913 lbh.adjustRightBearing(); 1914 if (lbh.checkFullOtherwiseExtend(line)) { 1915 if (!breakany) { 1916 line.textWidth += lbh.softHyphenWidth; 1917 } 1918 1919 goto found; 1920 } 1867 1921 } 1868 1869 if ((sb_or_ws|breakany) && lbh.checkFullOtherwiseExtend(line)) { 1870 if (!breakany) { 1871 line.textWidth += lbh.softHyphenWidth; 1872 } 1873 1874 line.textWidth += lbh.rightBearing; 1875 1876 goto found; 1877 } 1878 } 1879 if (pos == end) 1922 } 1923 if (lbh.currentPosition == end) 1880 1924 newItem = item + 1; 1881 1925 } 1882 1926 LB_DEBUG("reached end of line"); 1883 1927 lbh.checkFullOtherwiseExtend(line); 1884 line.textWidth += lbh.rightBearing;1885 1886 1928 found: 1929 if (lbh.rightBearing > 0) // If right bearing has not yet been adjusted 1930 lbh.adjustRightBearing(); 1931 line.textAdvance = line.textWidth; 1932 line.textWidth -= qMin(QFixed(), lbh.rightBearing); 1933 1887 1934 if (line.length == 0) { 1888 1935 LB_DEBUG("no break available in line, adding temp: length %d, width %f, space: length %d, width %f",
Note:
See TracChangeset
for help on using the changeset viewer.