Skip to content

Commit

Permalink
Merge pull request #205 from Iamposox/master
Browse files Browse the repository at this point in the history
Rotate text on 90,270 degrees
  • Loading branch information
Gankov authored Sep 23, 2021
2 parents 9a84d7a + 0b903e4 commit a445314
Show file tree
Hide file tree
Showing 9 changed files with 436 additions and 161 deletions.
190 changes: 165 additions & 25 deletions RdlDesign/DesignXmlDraw.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3111,27 +3111,43 @@ private void DrawString(string text, StyleInfo si, RectangleF r)
}

private void DrawString(string text, StyleInfo si, RectangleF r, bool bWrap)
{
switch (si.WritingMode)
{
case WritingModeEnum.lr_tb:
case WritingModeEnum.tb_rl:
DrawStringLRTBandTBRL(text, si, r, bWrap);
break;
case WritingModeEnum.tb_lr:
DrawStringTBLR(text, si, r, bWrap);
break;
default:
throw new NotSupportedException($"Writing mode {si.WritingMode} is not supported");
}
}

private void DrawStringLRTBandTBRL(string text, StyleInfo si, RectangleF r, bool bWrap)
{
if (!r.IntersectsWith(_clip))
return;

Font drawFont=null;
StringFormat drawFormat=null;
Brush drawBrush=null;
Font drawFont = null;
StringFormat drawFormat = null;
Brush drawBrush = null;
try
{
// STYLE
System.Drawing.FontStyle fs = 0;
FontStyle fs = 0;
if (si.FontStyle == FontStyleEnum.Italic)
fs |= System.Drawing.FontStyle.Italic;
fs |= FontStyle.Italic;

switch (si.TextDecoration)
{
case TextDecorationEnum.Underline:
fs |= System.Drawing.FontStyle.Underline;
fs |= FontStyle.Underline;
break;
case TextDecorationEnum.LineThrough:
fs |= System.Drawing.FontStyle.Strikeout;
fs |= FontStyle.Strikeout;
break;
case TextDecorationEnum.Overline:
case TextDecorationEnum.None:
Expand All @@ -3148,24 +3164,26 @@ private void DrawString(string text, StyleInfo si, RectangleF r, bool bWrap)
case FontWeightEnum.W700:
case FontWeightEnum.W800:
case FontWeightEnum.W900:
fs |= System.Drawing.FontStyle.Bold;
fs |= FontStyle.Bold;
break;
default:
break;
}
if (si.FontSize <= 0) // can't have zero length font; force to default

if (si.FontSize <= 0) // can't have zero length font; force to default
si.FontSize = 10;
try
{
drawFont = new Font(si.FontFamily, si.FontSize, fs); // si.FontSize already in points
}
catch (ArgumentException ae) // fonts that don't exist can throw exception; but we don't want it to
{
text = ae.Message; // show the error msg (allows report designer to see error)
drawFont = new Font("Arial", si.FontSize, fs); // if this throws exception; we'll let it
}
try
{
drawFont = new Font(si.FontFamily, si.FontSize, fs); // si.FontSize already in points
}
catch (ArgumentException ae) // fonts that don't exist can throw exception; but we don't want it to
{
text = ae.Message; // show the error msg (allows report designer to see error)
drawFont = new Font("Arial", si.FontSize, fs); // if this throws exception; we'll let it
}

// ALIGNMENT
drawFormat = new StringFormat();
drawFormat = new StringFormat();
if (!bWrap)
drawFormat.FormatFlags |= StringFormatFlags.NoWrap;
switch (si.TextAlign)
Expand All @@ -3181,11 +3199,13 @@ private void DrawString(string text, StyleInfo si, RectangleF r, bool bWrap)
drawFormat.Alignment = StringAlignment.Near;
break;
}

if (si.WritingMode == WritingModeEnum.tb_rl)
{
drawFormat.FormatFlags |= StringFormatFlags.DirectionRightToLeft;
drawFormat.FormatFlags |= StringFormatFlags.DirectionVertical;
}

switch (si.VerticalAlign)
{
case VerticalAlignEnum.Bottom:
Expand All @@ -3199,18 +3219,138 @@ private void DrawString(string text, StyleInfo si, RectangleF r, bool bWrap)
drawFormat.LineAlignment = StringAlignment.Near;
break;
}

// draw the background
DrawBackground(r, si);

// adjust drawing rectangle based on padding and adjusted for scrolling
RectangleF r2 = new RectangleF(r.Left + si.PaddingLeft - _hScroll,
r.Top + si.PaddingTop - _vScroll,
r.Width - si.PaddingLeft - si.PaddingRight,
r.Height - si.PaddingTop - si.PaddingBottom);

r.Top + si.PaddingTop - _vScroll,
r.Width - si.PaddingLeft - si.PaddingRight,
r.Height - si.PaddingTop - si.PaddingBottom);


drawBrush = new SolidBrush(si.Color);
g.DrawString(text, drawFont, drawBrush, r2, drawFormat);
}
finally
{
if (drawFont != null)
drawFont.Dispose();
if (drawFormat != null)
drawFont.Dispose();
if (drawBrush != null)
drawBrush.Dispose();
}

DrawBorder(si, r); // Draw the border if needed
}

private void DrawStringTBLR(string text, StyleInfo si, RectangleF r, bool bWrap)
{
if (!r.IntersectsWith(_clip))
return;

var restoreG = g.Save();
Font drawFont = null;
StringFormat drawFormat = null;
Brush drawBrush = null;
try
{
// STYLE
FontStyle fs = 0;
if (si.FontStyle == FontStyleEnum.Italic)
fs |= FontStyle.Italic;

switch (si.TextDecoration)
{
case TextDecorationEnum.Underline:
fs |= FontStyle.Underline;
break;
case TextDecorationEnum.LineThrough:
fs |= FontStyle.Strikeout;
break;
case TextDecorationEnum.Overline:
case TextDecorationEnum.None:
break;
}

// WEIGHT
switch (si.FontWeight)
{
case FontWeightEnum.Bold:
case FontWeightEnum.Bolder:
case FontWeightEnum.W500:
case FontWeightEnum.W600:
case FontWeightEnum.W700:
case FontWeightEnum.W800:
case FontWeightEnum.W900:
fs |= FontStyle.Bold;
break;
default:
break;
}

if (si.FontSize <= 0) // can't have zero length font; force to default
si.FontSize = 10;

try
{
drawFont = new Font(si.FontFamily, si.FontSize, fs); // si.FontSize already in points
}
catch (ArgumentException ae) // fonts that don't exist can throw exception; but we don't want it to
{
text = ae.Message; // show the error msg (allows report designer to see error)
drawFont = new Font("Arial", si.FontSize, fs); // if this throws exception; we'll let it
}

float fontsize = drawFont.Height / 96.0F * 72;

// ALIGNMENT
drawFormat = new StringFormat();
if (!bWrap)
drawFormat.FormatFlags |= StringFormatFlags.NoWrap;

float x = 0;

switch (si.VerticalAlign)
{
case VerticalAlignEnum.Top:
x = r.X + si.PaddingLeft;
break;
case VerticalAlignEnum.Middle:
x = r.X + (r.Width - fontsize) / 2;
break;
case VerticalAlignEnum.Bottom:
x = r.X + r.Width - fontsize - si.PaddingRight;
break;
}

var size = g.MeasureString(text, drawFont, r.Size, drawFormat);
float y = 0;
switch (si.TextAlign)
{
case TextAlignEnum.Left:
y = r.Y + r.Height - si.PaddingBottom;
break;
case TextAlignEnum.Center:
y = r.Y + (r.Height + size.Width - si.PaddingBottom + si.PaddingTop) / 2;
break;
case TextAlignEnum.Right:
y = r.Y + si.PaddingTop + size.Width;
break;
}

// draw the background
DrawBackground(r, si);

RectangleF r2 = new RectangleF(-y, x, r.Height - si.PaddingBottom - si.PaddingTop,
r.Width - si.PaddingLeft + si.PaddingRight);

drawBrush = new SolidBrush(si.Color);
g.RotateTransform(270.0F);
g.DrawString(text, drawFont, drawBrush, r2, drawFormat);
g.Restore(restoreG);
}
finally
{
Expand All @@ -3222,7 +3362,7 @@ private void DrawString(string text, StyleInfo si, RectangleF r, bool bWrap)
drawBrush.Dispose();
}

DrawBorder(si, r); // Draw the border if needed
DrawBorder(si, r); // Draw the border if needed
}

internal void PasteImage(XmlNode parent, System.Drawing.Bitmap img, PointF p)
Expand Down
3 changes: 2 additions & 1 deletion RdlDesign/FontCtl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,8 @@ private void InitializeComponent()
this.cbWritingMode.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cbWritingMode.Items.AddRange(new object[] {
resources.GetString("cbWritingMode.Items"),
resources.GetString("cbWritingMode.Items1")});
resources.GetString("cbWritingMode.Items1"),
resources.GetString("cbWritingMode.Items2")});
this.cbWritingMode.Name = "cbWritingMode";
this.cbWritingMode.SelectedIndexChanged += new System.EventHandler(this.cbWritingMode_TextChanged);
this.cbWritingMode.TextChanged += new System.EventHandler(this.cbWritingMode_TextChanged);
Expand Down
3 changes: 3 additions & 0 deletions RdlDesign/FontCtl.resx
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,9 @@
<data name="cbWritingMode.Items1" xml:space="preserve">
<value>tb-rl</value>
</data>
<data name="cbWritingMode.Items2" xml:space="preserve">
<value>tb-lr</value>
</data>
<data name="button2.TextAlign" type="System.Drawing.ContentAlignment, System.Drawing">
<value>MiddleLeft</value>
</data>
Expand Down
2 changes: 1 addition & 1 deletion RdlDesign/RdlProperties/PropertyAppearance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ public override StandardValuesCollection GetStandardValues(ITypeDescriptorContex
#region WritingMode
internal class WritingModeConverter : StringConverter
{
static readonly string[] WMList = new string[] { "lr-tb", "tb-rl" };
static readonly string[] WMList = new string[] { "lr-tb", "tb-rl", "tb-lr" };

public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
{
Expand Down
3 changes: 2 additions & 1 deletion RdlDesign/StyleTextCtl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,8 @@ private void InitializeComponent()
this.cbWritingMode.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cbWritingMode.Items.AddRange(new object[] {
resources.GetString("cbWritingMode.Items"),
resources.GetString("cbWritingMode.Items1")});
resources.GetString("cbWritingMode.Items1"),
resources.GetString("cbWritingMode.Items2")});
resources.ApplyResources(this.cbWritingMode, "cbWritingMode");
this.cbWritingMode.Name = "cbWritingMode";
this.cbWritingMode.SelectedIndexChanged += new System.EventHandler(this.cbWritingMode_TextChanged);
Expand Down
3 changes: 3 additions & 0 deletions RdlDesign/StyleTextCtl.resx
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,9 @@
<data name="cbWritingMode.Items1" xml:space="preserve">
<value>tb-rl</value>
</data>
<data name="cbWritingMode.Items2" xml:space="preserve">
<value>tb-lr</value>
</data>
<data name="button2.TextAlign" type="System.Drawing.ContentAlignment, System.Drawing">
<value>MiddleLeft</value>
</data>
Expand Down
23 changes: 22 additions & 1 deletion RdlEngine/Render/ExcelConverter/ExcelCellStyle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public ExcelCellStyle(StyleInfo fromStyle)
SetFontStyle(fromStyle.FontStyle);
SetTextDecoration(fromStyle.TextDecoration);
SetFontColor(fromStyle.Color);

SetWritingMode(fromStyle.WritingMode);
}

public void SetToStyle(XSSFCellStyle style)
Expand All @@ -50,6 +50,20 @@ public void SetToStyle(XSSFCellStyle style)

style.VerticalAlignment = VerticalAlignment;
style.Alignment = HorizontalAlignment;
switch (_writingMode)
{
case WritingModeEnum.lr_tb:
style.Rotation = 0;
break;
case WritingModeEnum.tb_rl:
style.Rotation = -90;
break;
case WritingModeEnum.tb_lr:
style.Rotation = 90;
break;
default:
throw new ArgumentOutOfRangeException($"Writing mode {_writingMode} is not supported");
}
}

public void SetToFont(XSSFFont font)
Expand Down Expand Up @@ -272,6 +286,13 @@ public BorderStyle BorderLeft {
}
}

private WritingModeEnum _writingMode;

public void SetWritingMode(WritingModeEnum writingMode)
{
_writingMode = writingMode;
}

public bool CompareWithXSSFFont(XSSFFont font)
{
if(FontName != font.FontName) {
Expand Down
9 changes: 7 additions & 2 deletions RdlEngine/Runtime/StyleInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,10 @@ public static WritingModeEnum GetWritingMode(string v, WritingModeEnum def)
{
v = "lr_tb";
}
else if (v == "tb-lr")
{
v = "tb_lr";
}
w = (WritingModeEnum)Enum.Parse(typeof(WritingModeEnum), v);
}
catch
Expand Down Expand Up @@ -844,8 +848,9 @@ public enum DirectionEnum

public enum WritingModeEnum
{
lr_tb, // left right - top bottom
tb_rl // top bottom - right left
lr_tb, // left right - top bottom
tb_rl, // top bottom - right left
tb_lr // top bottom - left right
}

public enum UnicodeBiDirectionalEnum
Expand Down
Loading

0 comments on commit a445314

Please sign in to comment.