Skip to content

Commit 44ccea9

Browse files
committed
Issue #932: new api: StyledText.setFixedLineMetrics
To be implemented in next commits Signed-off-by: Alexandr Miloslavskiy <[email protected]>
1 parent 6e9017e commit 44ccea9

File tree

5 files changed

+125
-0
lines changed

5 files changed

+125
-0
lines changed

bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8751,6 +8751,15 @@ private boolean hasMultipleCarets() {
87518751
return carets != null && carets.length > 1;
87528752
}
87538753

8754+
/**
8755+
* See {@link TextLayout#setFixedLineMetrics}
8756+
*
8757+
* @since 3.125
8758+
*/
8759+
public void setFixedLineMetrics(FontMetrics metrics) {
8760+
renderer.setFixedLineMetrics (metrics);
8761+
}
8762+
87548763
/**
87558764
* Sets a new font to render text with.
87568765
* <p>

bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextRenderer.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ class StyledTextRenderer {
3636
StyledTextLineSpacingProvider lineSpacingProvider;
3737
boolean lineSpacingComputing;
3838

39+
/* Custom line metrics */
40+
private FontMetrics fixedLineMetrics;
41+
3942
/* Font info */
4043
Font regularFont, boldFont, italicFont, boldItalicFont;
4144
int tabWidth;
@@ -1193,6 +1196,7 @@ TextLayout getTextLayout(int lineIndex, int orientation, int width, int lineSpac
11931196
layout.setFont(regularFont);
11941197
layout.setAscent(ascent);
11951198
layout.setDescent(descent);
1199+
layout.setFixedLineMetrics(fixedLineMetrics);
11961200
layout.setText(line);
11971201
layout.setOrientation(orientation);
11981202
layout.setSegments(segments);
@@ -1378,6 +1382,16 @@ void setContent(StyledTextContent content) {
13781382
maxWidthLineIndex = -1;
13791383
reset(0, lineCount);
13801384
}
1385+
1386+
/**
1387+
* See {@link TextLayout#setFixedLineMetrics}
1388+
*
1389+
* @since 3.125
1390+
*/
1391+
public void setFixedLineMetrics(FontMetrics metrics) {
1392+
fixedLineMetrics = metrics;
1393+
}
1394+
13811395
void setFont(Font font, int tabs) {
13821396
TextLayout layout = new TextLayout(device);
13831397
layout.setFont(regularFont);

bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/TextLayout.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,6 +1768,40 @@ public void setDescent (int descent) {
17681768
}
17691769
}
17701770

1771+
/**
1772+
* Forces line heights in receiver to obey provided value. This is
1773+
* useful with texts that contain glyphs from different scripts,
1774+
* such as mixing latin glyphs with hieroglyphs or emojis.
1775+
* <p>
1776+
* Text lines with different metrics will be forced to fit. This means
1777+
* painting text in such a way that its baseline is where specified by
1778+
* given 'metrics'. This can sometimes introduce small visual artifacs,
1779+
* such as taller lines overpainting or being clipped by content above
1780+
* and below.
1781+
* </p>
1782+
* The possible ways to set FontMetrics include:
1783+
* <ul>
1784+
* <li>Obtaining 'FontMetrics' via {@link GC#getFontMetrics}. Note that
1785+
* this will only obtain metrics for currently selected font and will not
1786+
* account for font fallbacks (for example, with a latin font selected,
1787+
* painting hieroglyphs usually involves a fallback font).</li>
1788+
* <li>Obtaining 'FontMetrics' via a temporary 'TextLayout'. This would
1789+
* involve setting a desired text sample to 'TextLayout', then measuring
1790+
* it with {@link org.eclipse.swt.graphics.TextLayout#getLineMetrics(int)}. This approach will also
1791+
* take fallback fonts into account.</li>
1792+
* </ul>
1793+
*
1794+
* NOTE: Does not currently support (as in, undefined behavior) multi-line
1795+
* layouts, including those caused by word wrapping. StyledText uses one
1796+
* TextLayout per line and is only affected by word wrap restriction.
1797+
*
1798+
* @since 3.125
1799+
*/
1800+
public void setFixedLineMetrics (FontMetrics metrics) {
1801+
if (metrics == null) return;
1802+
SWT.error(SWT.ERROR_NOT_IMPLEMENTED);
1803+
}
1804+
17711805
/**
17721806
* Sets the default font which will be used by the receiver
17731807
* to draw and measure text. If the

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/TextLayout.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,6 +1798,40 @@ public void setDescent (int descent) {
17981798
this.descentInPoints = descent;
17991799
}
18001800

1801+
/**
1802+
* Forces line heights in receiver to obey provided value. This is
1803+
* useful with texts that contain glyphs from different scripts,
1804+
* such as mixing latin glyphs with hieroglyphs or emojis.
1805+
* <p>
1806+
* Text lines with different metrics will be forced to fit. This means
1807+
* painting text in such a way that its baseline is where specified by
1808+
* given 'metrics'. This can sometimes introduce small visual artifacs,
1809+
* such as taller lines overpainting or being clipped by content above
1810+
* and below.
1811+
* </p>
1812+
* The possible ways to set FontMetrics include:
1813+
* <ul>
1814+
* <li>Obtaining 'FontMetrics' via {@link GC#getFontMetrics}. Note that
1815+
* this will only obtain metrics for currently selected font and will not
1816+
* account for font fallbacks (for example, with a latin font selected,
1817+
* painting hieroglyphs usually involves a fallback font).</li>
1818+
* <li>Obtaining 'FontMetrics' via a temporary 'TextLayout'. This would
1819+
* involve setting a desired text sample to 'TextLayout', then measuring
1820+
* it with {@link org.eclipse.swt.graphics.TextLayout#getLineMetrics(int)}. This approach will also
1821+
* take fallback fonts into account.</li>
1822+
* </ul>
1823+
*
1824+
* NOTE: Does not currently support (as in, undefined behavior) multi-line
1825+
* layouts, including those caused by word wrapping. StyledText uses one
1826+
* TextLayout per line and is only affected by word wrap restriction.
1827+
*
1828+
* @since 3.125
1829+
*/
1830+
public void setFixedLineMetrics (FontMetrics metrics) {
1831+
if (metrics == null) return;
1832+
SWT.error(SWT.ERROR_NOT_IMPLEMENTED);
1833+
}
1834+
18011835
/**
18021836
* Sets the default font which will be used by the receiver
18031837
* to draw and measure text. If the

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/TextLayout.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3078,6 +3078,40 @@ public void setDescent (int descent) {
30783078
this.descentInPixels = descent;
30793079
}
30803080

3081+
/**
3082+
* Forces line heights in receiver to obey provided value. This is
3083+
* useful with texts that contain glyphs from different scripts,
3084+
* such as mixing latin glyphs with hieroglyphs or emojis.
3085+
* <p>
3086+
* Text lines with different metrics will be forced to fit. This means
3087+
* painting text in such a way that its baseline is where specified by
3088+
* given 'metrics'. This can sometimes introduce small visual artifacs,
3089+
* such as taller lines overpainting or being clipped by content above
3090+
* and below.
3091+
* </p>
3092+
* The possible ways to set FontMetrics include:
3093+
* <ul>
3094+
* <li>Obtaining 'FontMetrics' via {@link GC#getFontMetrics}. Note that
3095+
* this will only obtain metrics for currently selected font and will not
3096+
* account for font fallbacks (for example, with a latin font selected,
3097+
* painting hieroglyphs usually involves a fallback font).</li>
3098+
* <li>Obtaining 'FontMetrics' via a temporary 'TextLayout'. This would
3099+
* involve setting a desired text sample to 'TextLayout', then measuring
3100+
* it with {@link TextLayout#getLineMetrics(int)}. This approach will also
3101+
* take fallback fonts into account.</li>
3102+
* </ul>
3103+
*
3104+
* NOTE: Does not currently support (as in, undefined behavior) multi-line
3105+
* layouts, including those caused by word wrapping. StyledText uses one
3106+
* TextLayout per line and is only affected by word wrap restriction.
3107+
*
3108+
* @since 3.125
3109+
*/
3110+
public void setFixedLineMetrics (FontMetrics metrics) {
3111+
if (metrics == null) return;
3112+
SWT.error(SWT.ERROR_NOT_IMPLEMENTED);
3113+
}
3114+
30813115
/**
30823116
* Sets the default font which will be used by the receiver
30833117
* to draw and measure text. If the

0 commit comments

Comments
 (0)