Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/mcs/class
diff options
context:
space:
mode:
authorKarl <karl@scowencomputers.co.nz>2015-09-12 09:14:50 +0300
committerKarl <karl@scowencomputers.co.nz>2020-01-13 06:42:44 +0300
commitdbf98ffc93645e1e364ec16cf0ce371cac6a4edb (patch)
tree015cf2f672d249eae7b22834fcf5c2cc7cdd8ecf /mcs/class
parentf25ca77bfecf98da5f195b94e8e09e2d847c521b (diff)
Add line spacing support. Move dpi to TextControl.
Line spacing seems to be working perfectly.
Diffstat (limited to 'mcs/class')
-rw-r--r--mcs/class/System.Windows.Forms/System.Windows.Forms/Line.cs45
-rw-r--r--mcs/class/System.Windows.Forms/System.Windows.Forms/LineTag.cs2
-rw-r--r--mcs/class/System.Windows.Forms/System.Windows.Forms/RichTextBox.cs86
-rw-r--r--mcs/class/System.Windows.Forms/System.Windows.Forms/TextBoxBase.cs2
4 files changed, 100 insertions, 35 deletions
diff --git a/mcs/class/System.Windows.Forms/System.Windows.Forms/Line.cs b/mcs/class/System.Windows.Forms/System.Windows.Forms/Line.cs
index 71b2dd528e8..f93e629df7e 100644
--- a/mcs/class/System.Windows.Forms/System.Windows.Forms/Line.cs
+++ b/mcs/class/System.Windows.Forms/System.Windows.Forms/Line.cs
@@ -45,7 +45,8 @@ namespace System.Windows.Forms
internal int line_no; // Line number
internal LineTag tags; // Tags describing the text
internal int offset; // Baseline can be on the X or Y axis depending if we are in multiline mode or not
- internal int height; // Total height of the line, including spacing_before and spacing_after
+ internal int height; // Total height of the line, including TotalParagraphSpacing and LineSpacing
+ private int textHeight; // Height of the line without spacing.
internal int ascent; // Ascent of the line (highest distance above the baseline, including character offset)
internal HorizontalAlignment alignment; // Alignment of the line
internal int align_shift; // Pixel shift caused by the alignment
@@ -55,6 +56,8 @@ namespace System.Windows.Forms
internal LineEnding ending;
internal int spacing_before;
internal int spacing_after;
+ internal int line_spacing;
+ internal bool line_spacing_multiple;
internal int[] tab_stops; // Custom tabstops for this paragraph.
// Stuff that's important for the tree
@@ -120,8 +123,8 @@ namespace System.Windows.Forms
internal Line (Document document, int LineNo, string Text, HorizontalAlignment align, Font font, Color color,
Color back_color, TextPositioning text_position, int char_offset, int left_indent, int hanging_indent,
- int right_indent, int spacing_before, int spacing_after, int[] tab_stops, bool visible, LineEnding ending)
- : this(document, ending)
+ int right_indent, int spacing_before, int spacing_after, int line_spacing, bool line_spacing_multiple,
+ int[] tab_stops, bool visible, LineEnding ending) : this(document, ending)
{
space = Text.Length > DEFAULT_TEXT_LEN ? Text.Length+1 : DEFAULT_TEXT_LEN;
@@ -135,6 +138,8 @@ namespace System.Windows.Forms
this.spacing_before = spacing_before;
this.spacing_after = spacing_after;
this.tab_stops = tab_stops;
+ this.line_spacing = line_spacing;
+ this.line_spacing_multiple = line_spacing_multiple;
widths = new float[space + 1];
@@ -190,17 +195,38 @@ namespace System.Windows.Forms
set { height = value; }
}
+ internal int TextHeight {
+ get {
+ return textHeight;
+ }
+ }
+
internal int[] TabStops {
get { return tab_stops; }
set { tab_stops = value; }
}
- internal int TotalSpacing {
+ internal int TotalParagraphSpacing {
get {
return SpacingBefore + SpacingAfter;
}
}
+ internal int LineSpacing {
+ get {
+ if (textHeight == 0) {
+ throw new InvalidOperationException("Can't get LineSpacing when the line height isn't calculated!");
+ }
+ if (line_spacing < 0) {
+ return -line_spacing;
+ } else if (line_spacing_multiple) {
+ return (int)(line_spacing * textHeight * 6f / document.dpi);
+ } else {
+ return Math.Max(line_spacing, textHeight);
+ }
+ }
+ }
+
internal int SpacingBefore {
get {
bool has_spacing = true;
@@ -750,7 +776,8 @@ namespace System.Windows.Forms
tags.Shift = 0;
}
- this.height += this.TotalSpacing;
+ this.textHeight = this.height;
+ this.height = this.LineSpacing + this.TotalParagraphSpacing;
if (prev_offset != offset || prev_height != this.height || prev_ascent != this.ascent ||
prev_spacing_before != this.SpacingBefore)
@@ -781,14 +808,14 @@ namespace System.Windows.Forms
w = TextBoxTextRenderer.MeasureText (g, doc.password_char, tags.Font).Width;
- if (this.height - this.TotalSpacing != (int)tag.Font.Height)
+ if (this.textHeight != (int)tag.Font.Height)
ret = true;
else
ret = false;
- this.height = (int)tag.Font.Height;
- tag.Height = this.height;
- this.height += this.TotalSpacing;
+ this.textHeight = (int)tag.Font.Height;
+ tag.Height = this.textHeight;
+ this.height = this.textHeight + this.LineSpacing + this.TotalParagraphSpacing;
this.ascent = tag.Ascent;
diff --git a/mcs/class/System.Windows.Forms/System.Windows.Forms/LineTag.cs b/mcs/class/System.Windows.Forms/System.Windows.Forms/LineTag.cs
index bac5c3cfe72..70de2ebfd8e 100644
--- a/mcs/class/System.Windows.Forms/System.Windows.Forms/LineTag.cs
+++ b/mcs/class/System.Windows.Forms/System.Windows.Forms/LineTag.cs
@@ -504,7 +504,7 @@ namespace System.Windows.Forms
bool retval = false; // Assume line-height doesn't change
// Too simple?
- if (((FormatSpecified.Font & specified) == FormatSpecified.Font) && font.Height != line.height - line.TotalSpacing)
+ if (((FormatSpecified.Font & specified) == FormatSpecified.Font) && font.Height != line.TextHeight)
retval = true;
line.recalc = true; // This forces recalculation of the line in RecalculateDocument
diff --git a/mcs/class/System.Windows.Forms/System.Windows.Forms/RichTextBox.cs b/mcs/class/System.Windows.Forms/System.Windows.Forms/RichTextBox.cs
index cadee537a96..bafacd7634d 100644
--- a/mcs/class/System.Windows.Forms/System.Windows.Forms/RichTextBox.cs
+++ b/mcs/class/System.Windows.Forms/System.Windows.Forms/RichTextBox.cs
@@ -69,7 +69,6 @@ namespace System.Windows.Forms {
private RichTextBoxLanguageOptions language_option;
private bool rich_text_shortcuts_enabled;
- private readonly float dpi; // Store the dpi so we don't have to create a Graphics object to calculate this frequently. Needed to read or write RTF sizes.
//private Color selection_back_color; // We don't actually need this now.
#endregion // Local Variables
@@ -110,9 +109,6 @@ namespace System.Windows.Forms {
base.VScrolled += new EventHandler(RichTextBox_VScrolled);
SetStyle (ControlStyles.StandardDoubleClick, false);
-
- using (Graphics g = CreateGraphics())
- dpi = (g.DpiX + g.DpiY) / 2;
}
#endregion // Public Constructors
@@ -1629,6 +1625,8 @@ namespace System.Windows.Forms {
internal int rtf_skip_width;
internal int rtf_par_spacing_after;
internal int rtf_par_spacing_before;
+ internal int rtf_par_line_spacing;
+ internal bool rtf_par_line_spacing_multiple;
internal TextPositioning rtf_text_position;
internal int rtf_char_offset;
internal ArrayList rtf_par_tab_stops = new ArrayList();
@@ -1650,6 +1648,8 @@ namespace System.Windows.Forms {
new_style.rtf_skip_width = rtf_skip_width;
new_style.rtf_par_spacing_after = rtf_par_spacing_after;
new_style.rtf_par_spacing_before = rtf_par_spacing_before;
+ new_style.rtf_par_line_spacing = rtf_par_line_spacing;
+ new_style.rtf_par_line_spacing_multiple = rtf_par_line_spacing_multiple;
new_style.rtf_text_position = rtf_text_position;
new_style.rtf_char_offset = rtf_char_offset;
new_style.rtf_par_tab_stops.AddRange (rtf_par_tab_stops);
@@ -1848,13 +1848,13 @@ namespace System.Windows.Forms {
case RTF.Minor.SuperScript: {
FlushText (rtf, false);
- rtf_style.rtf_char_offset = (int) (((float) rtf.Param / 144.0F) * dpi + 0.5F);
+ rtf_style.rtf_char_offset = (int) (((float) rtf.Param / 144.0F) * document.dpi + 0.5F);
break;
}
case RTF.Minor.SubScript: {
FlushText (rtf, false);
- rtf_style.rtf_char_offset = -(int) (((float) rtf.Param / 144.0F) * dpi + 0.5F);
+ rtf_style.rtf_char_offset = -(int) (((float) rtf.Param / 144.0F) * document.dpi + 0.5F);
break;
}
}
@@ -1865,30 +1865,32 @@ namespace System.Windows.Forms {
switch (rtf.Minor) {
case RTF.Minor.ParDef:
- FlushText (rtf, false);
+ FlushText(rtf, false);
rtf_style.rtf_par_line_left_indent = 0;
rtf_style.rtf_par_first_line_indent = 0;
rtf_style.rtf_par_line_right_indent = 0;
rtf_style.rtf_par_spacing_after = 0;
rtf_style.rtf_par_spacing_before = 0;
+ rtf_style.rtf_par_line_spacing = 0;
+ rtf_style.rtf_par_line_spacing_multiple = false;
rtf_style.rtf_rtfalign = HorizontalAlignment.Left;
rtf_style.rtf_par_tab_stops.Clear ();
break;
case RTF.Minor.TabPos:
- rtf_style.rtf_par_tab_stops.Add((int) (((float) rtf.Param / 1440.0F) * dpi + 0.5F));
+ rtf_style.rtf_par_tab_stops.Add((int) (((float) rtf.Param / 1440.0F) * document.dpi + 0.5F));
break;
case RTF.Minor.LeftIndent:
- rtf_style.rtf_par_line_left_indent = (int) (((float) rtf.Param / 1440.0F) * dpi + 0.5F);
+ rtf_style.rtf_par_line_left_indent = (int) (((float) rtf.Param / 1440.0F) * document.dpi + 0.5F);
break;
case RTF.Minor.FirstIndent:
- rtf_style.rtf_par_first_line_indent = (int) (((float) rtf.Param / 1440.0F) * dpi + 0.5F);
+ rtf_style.rtf_par_first_line_indent = (int) (((float) rtf.Param / 1440.0F) * document.dpi + 0.5F);
break;
case RTF.Minor.RightIndent:
- rtf_style.rtf_par_line_right_indent = (int) (((float) rtf.Param / 1440.0F) * dpi + 0.5F);
+ rtf_style.rtf_par_line_right_indent = (int) (((float) rtf.Param / 1440.0F) * document.dpi + 0.5F);
break;
case RTF.Minor.QuadCenter:
@@ -1912,13 +1914,20 @@ namespace System.Windows.Forms {
break;
case RTF.Minor.SpaceAfter:
- rtf_style.rtf_par_spacing_after = (int) (((float) rtf.Param / 1440.0F) * dpi + 0.5F);
+ rtf_style.rtf_par_spacing_after = (int) (((float) rtf.Param / 1440.0F) * document.dpi + 0.5F);
break;
case RTF.Minor.SpaceBefore:
- rtf_style.rtf_par_spacing_before = (int) (((float) rtf.Param / 1440.0F) * dpi + 0.5F);
+ rtf_style.rtf_par_spacing_before = (int) (((float) rtf.Param / 1440.0F) * document.dpi + 0.5F);
break;
+ case RTF.Minor.SpaceBetween:
+ rtf_style.rtf_par_line_spacing = (int) (((float) rtf.Param / 1440.0F) * document.dpi + 0.5F);
+ break;
+
+ case RTF.Minor.SpaceMultiply:
+ rtf_style.rtf_par_line_spacing_multiple = (rtf.Param == 1);
+ break;
}
break;
}
@@ -2089,6 +2098,7 @@ namespace System.Windows.Forms {
document.Add (rtf_cursor_y, rtf_line.ToString (), rtf_style.rtf_rtfalign, font, rtf_style.rtf_color,
rtf_style.rtf_back_color, rtf_style.rtf_text_position, rtf_style.rtf_char_offset, left_indent, hanging_indent,
rtf_style.rtf_par_line_right_indent, rtf_style.rtf_par_spacing_before, rtf_style.rtf_par_spacing_after,
+ rtf_style.rtf_par_line_spacing, rtf_style.rtf_par_line_spacing_multiple,
(int[]) rtf_style.rtf_par_tab_stops.ToArray(typeof (int)) , rtf_style.rtf_visible,
newline ? LineEnding.Rich : LineEnding.None);
} else {
@@ -2105,6 +2115,8 @@ namespace System.Windows.Forms {
line.right_indent = Math.Max (rtf_style.rtf_par_line_right_indent, line.right_indent);
line.spacing_after = Math.Max (rtf_style.rtf_par_spacing_after, line.spacing_after);
line.spacing_before = Math.Max (rtf_style.rtf_par_spacing_before, line.spacing_before);
+ line.line_spacing = Math.Max (rtf_style.rtf_par_line_spacing, line.line_spacing);
+ line.line_spacing_multiple = rtf_style.rtf_par_line_spacing_multiple;
line.alignment = rtf_style.rtf_rtfalign;
if (rtf_line.Length > 0) {
@@ -2158,6 +2170,8 @@ namespace System.Windows.Forms {
rtf_style.rtf_text_position = TextPositioning.Normal;
rtf_style.rtf_par_spacing_after = 0;
rtf_style.rtf_par_spacing_before = 0;
+ rtf_style.rtf_par_line_spacing = 0;
+ rtf_style.rtf_par_line_spacing_multiple = false;
rtf_style.rtf_par_line_left_indent = 0;
rtf_style.rtf_par_first_line_indent = 0;
rtf_style.rtf_par_line_right_indent = 0;
@@ -2361,6 +2375,8 @@ namespace System.Windows.Forms {
HorizontalAlignment line_alignment;
int spacing_after;
int spacing_before;
+ int line_spacing;
+ bool line_spacing_multiple;
int left_indent;
int prev_left_indent;
int first_line_indent;
@@ -2482,6 +2498,8 @@ namespace System.Windows.Forms {
pos = start_pos;
spacing_after = line.spacing_after;
spacing_before = line.spacing_before;
+ line_spacing = line.line_spacing;
+ line_spacing_multiple = line.line_spacing_multiple;
line_alignment = line.alignment;
first_line_indent = -line.HangingIndent;
left_indent = line.Indent - first_line_indent;
@@ -2504,23 +2522,29 @@ namespace System.Windows.Forms {
}
if (line.spacing_after != 0) {
sb.Append("\\sa");
- sb.Append((line.spacing_after / dpi) * 1440);
+ sb.Append((line.spacing_after / document.dpi) * 1440);
}
if (line.spacing_before != 0) {
sb.Append("\\sb");
- sb.Append((line.spacing_before / dpi) * 1440);
+ sb.Append((line.spacing_before / document.dpi) * 1440);
+ }
+ if (line.line_spacing != 0) {
+ sb.Append("\\sl");
+ sb.Append((line.line_spacing / document.dpi) * 1440);
+ sb.Append("\\slmult");
+ sb.Append(line.line_spacing_multiple ? "1" : "0");
}
if (left_indent != 0) {
sb.Append("\\li");
- sb.Append(((left_indent) / dpi) * 1440);
+ sb.Append(((left_indent) / document.dpi) * 1440);
}
if (first_line_indent != 0) {
sb.Append("\\fi");
- sb.Append((first_line_indent / dpi) * 1440);
+ sb.Append((first_line_indent / document.dpi) * 1440);
}
if (line.right_indent != 0) {
sb.Append("\\ri");
- sb.Append((line.right_indent / dpi) * 1440);
+ sb.Append((line.right_indent / document.dpi) * 1440);
}
EmitRTFFontProperties(sb, -1, fonts.IndexOf(tag.Font.Name), null, tag.Font); // Font properties
sb.Append(" "); // Space separator
@@ -2555,13 +2579,25 @@ namespace System.Windows.Forms {
if (line.spacing_after != spacing_after) {
spacing_after = line.spacing_after;
sb.Append("\\sa");
- sb.Append((int) ((spacing_after / dpi) * 1440));
+ sb.Append((int) ((spacing_after / document.dpi) * 1440));
}
if (line.spacing_before != spacing_before) {
spacing_before = line.spacing_before;
sb.Append("\\sb");
- sb.Append((int) ((spacing_before / dpi) * 1440));
+ sb.Append((int) ((spacing_before / document.dpi) * 1440));
+ }
+
+ if (line.line_spacing != line_spacing) {
+ line_spacing = line.line_spacing;
+ sb.Append("\\sl");
+ sb.Append((line.line_spacing / document.dpi) * 1440);
+ }
+
+ if (line.line_spacing_multiple != line_spacing_multiple) {
+ line_spacing_multiple = line.line_spacing_multiple;
+ sb.Append("\\slmult");
+ sb.Append(line.line_spacing_multiple ? "1" : "0");
}
first_line_indent = -line.HangingIndent;
@@ -2570,19 +2606,19 @@ namespace System.Windows.Forms {
if (prev_left_indent != left_indent) {
prev_left_indent = left_indent;
sb.Append("\\li");
- sb.Append((left_indent / dpi) * 1440);
+ sb.Append((left_indent / document.dpi) * 1440);
}
if (prev_first_line_indent != first_line_indent) {
prev_first_line_indent = first_line_indent;
sb.Append("\\fi");
- sb.Append((first_line_indent / dpi) * 1440);
+ sb.Append((first_line_indent / document.dpi) * 1440);
}
if (line.right_indent != right_indent) {
right_indent = line.right_indent;
sb.Append("\\ri");
- sb.Append((right_indent / dpi) * 1440);
+ sb.Append((right_indent / document.dpi) * 1440);
}
if (length != sb.Length) {
@@ -2632,10 +2668,10 @@ namespace System.Windows.Forms {
char_offset = tag.CharOffset;
if (char_offset >= 0) {
sb.Append("\\up");
- sb.Append((int) ((char_offset / dpi) * 144));
+ sb.Append((int) ((char_offset / document.dpi) * 144));
} else {
sb.Append("\\dn");
- sb.Append(-(int) ((char_offset / dpi) * 144));
+ sb.Append(-(int) ((char_offset / document.dpi) * 144));
}
}
diff --git a/mcs/class/System.Windows.Forms/System.Windows.Forms/TextBoxBase.cs b/mcs/class/System.Windows.Forms/System.Windows.Forms/TextBoxBase.cs
index af27bc37659..53f9b134f5e 100644
--- a/mcs/class/System.Windows.Forms/System.Windows.Forms/TextBoxBase.cs
+++ b/mcs/class/System.Windows.Forms/System.Windows.Forms/TextBoxBase.cs
@@ -166,6 +166,8 @@ namespace System.Windows.Forms
Cursor = Cursors.IBeam;
+ using (Graphics g = CreateGraphics())
+ document.dpi = (g.DpiX + g.DpiY) / 2;
requested_height = Height;
can_cache_preferred_size = true;