Commit 9960f2c9 authored by Eric Domke's avatar Eric Domke
Browse files

Iteration 3 of tspan functionality

- Begin allowing character positioning within a text element
- Start fixing bugs with linear gradients
parent 968a8f43
...@@ -197,7 +197,7 @@ namespace Svg ...@@ -197,7 +197,7 @@ namespace Svg
var distanceFromEffectiveStart = CalculateDistance(effectiveStart, originalPoint); var distanceFromEffectiveStart = CalculateDistance(effectiveStart, originalPoint);
colorBlend.Positions[i] = (float) Math.Max(0F, Math.Min((distanceFromEffectiveStart / effectiveLength), 1.0F)); colorBlend.Positions[i] = (float)Math.Round(Math.Max(0F, Math.Min((distanceFromEffectiveStart / effectiveLength), 1.0F)), 5);
} }
if (startDelta > 0) if (startDelta > 0)
......
...@@ -19,10 +19,10 @@ namespace Svg ...@@ -19,10 +19,10 @@ namespace Svg
public abstract class SvgTextBase : SvgVisualElement public abstract class SvgTextBase : SvgVisualElement
{ {
private SvgUnit _x; private SvgUnitCollection _x = new SvgUnitCollection();
private SvgUnit _y; private SvgUnitCollection _y = new SvgUnitCollection();
private SvgUnit _dy; private SvgUnitCollection _dy = new SvgUnitCollection();
private SvgUnit _dx; private SvgUnitCollection _dx = new SvgUnitCollection();
private SvgUnit _letterSpacing; private SvgUnit _letterSpacing;
private SvgUnit _wordSpacing; private SvgUnit _wordSpacing;
private SvgTextAnchor _textAnchor = SvgTextAnchor.Start; private SvgTextAnchor _textAnchor = SvgTextAnchor.Start;
...@@ -40,15 +40,6 @@ namespace Svg ...@@ -40,15 +40,6 @@ namespace Svg
_stringMeasure = SvgRenderer.FromImage(bitmap); _stringMeasure = SvgRenderer.FromImage(bitmap);
_stringMeasure.TextRenderingHint = TextRenderingHint.AntiAlias; _stringMeasure.TextRenderingHint = TextRenderingHint.AntiAlias;
} }
/// <summary>
/// Initializes a new instance of the <see cref="SvgTextBase"/> class.
/// </summary>
public SvgTextBase()
{
this._dy = new SvgUnit(0.0f);
this._dx = new SvgUnit(0.0f);
}
/// <summary> /// <summary>
/// Gets or sets the text to be rendered. /// Gets or sets the text to be rendered.
...@@ -75,7 +66,7 @@ namespace Svg ...@@ -75,7 +66,7 @@ namespace Svg
/// </summary> /// </summary>
/// <value>The X.</value> /// <value>The X.</value>
[SvgAttribute("x")] [SvgAttribute("x")]
public virtual SvgUnit X public virtual SvgUnitCollection X
{ {
get { return this._x; } get { return this._x; }
set set
...@@ -94,7 +85,7 @@ namespace Svg ...@@ -94,7 +85,7 @@ namespace Svg
/// </summary> /// </summary>
/// <value>The dX.</value> /// <value>The dX.</value>
[SvgAttribute("dx")] [SvgAttribute("dx")]
public virtual SvgUnit Dx public virtual SvgUnitCollection Dx
{ {
get { return this._dx; } get { return this._dx; }
set set
...@@ -113,7 +104,7 @@ namespace Svg ...@@ -113,7 +104,7 @@ namespace Svg
/// </summary> /// </summary>
/// <value>The Y.</value> /// <value>The Y.</value>
[SvgAttribute("y")] [SvgAttribute("y")]
public virtual SvgUnit Y public virtual SvgUnitCollection Y
{ {
get { return this._y; } get { return this._y; }
set set
...@@ -132,7 +123,7 @@ namespace Svg ...@@ -132,7 +123,7 @@ namespace Svg
/// </summary> /// </summary>
/// <value>The dY.</value> /// <value>The dY.</value>
[SvgAttribute("dy")] [SvgAttribute("dy")]
public virtual SvgUnit Dy public virtual SvgUnitCollection Dy
{ {
get { return this._dy; } get { return this._dy; }
set set
...@@ -288,6 +279,26 @@ namespace Svg ...@@ -288,6 +279,26 @@ namespace Svg
var nodes = (from n in this.Nodes var nodes = (from n in this.Nodes
where (n is SvgContentNode || n is SvgTextBase) && !string.IsNullOrEmpty(n.Content) where (n is SvgContentNode || n is SvgTextBase) && !string.IsNullOrEmpty(n.Content)
select n).ToList(); select n).ToList();
if (nodes.FirstOrDefault() is SvgContentNode && _x.Count > 1)
{
string ch;
var content = nodes.First() as SvgContentNode;
nodes.RemoveAt(0);
int posCount = Math.Min(content.Content.Length, _x.Count);
var text = PrepareText(content.Content, false, (nodes.Count > 1 && nodes[1] is SvgTextBase));
for (var i = 0; i < posCount; i++)
{
ch = (i == posCount - 1 ? text.Substring(i) : text.Substring(i, 1));
stringBounds = _stringMeasure.MeasureString(ch, font);
totalHeight = Math.Max(totalHeight, stringBounds.Height);
result.Nodes.Add(new NodeBounds() { Bounds = stringBounds,
Node = new SvgContentNode() { Content = ch},
xOffset = (i == 0 ? 0 : _x[i].ToDeviceValue(this) - _x[0].ToDeviceValue(this))});
}
}
ISvgNode node; ISvgNode node;
for (var i = 0; i < nodes.Count; i++) for (var i = 0; i < nodes.Count; i++)
{ {
...@@ -306,7 +317,7 @@ namespace Svg ...@@ -306,7 +317,7 @@ namespace Svg
{ {
stringBounds = innerText.GetTextBounds().Bounds; stringBounds = innerText.GetTextBounds().Bounds;
result.Nodes.Add(new NodeBounds() { Bounds = stringBounds, Node = node, xOffset = totalWidth }); result.Nodes.Add(new NodeBounds() { Bounds = stringBounds, Node = node, xOffset = totalWidth });
totalWidth += innerText.Dx.ToDeviceValue(this); if (innerText.Dx.Count == 1) totalWidth += innerText.Dx[0].ToDeviceValue(this);
} }
totalHeight = Math.Max(totalHeight, stringBounds.Height); totalHeight = Math.Max(totalHeight, stringBounds.Height);
totalWidth += stringBounds.Width; totalWidth += stringBounds.Width;
...@@ -336,18 +347,17 @@ namespace Svg ...@@ -336,18 +347,17 @@ namespace Svg
if (_path == null || this.IsPathDirty) if (_path == null || this.IsPathDirty)
{ {
// Measure the overall bounds of all the text
var boundsData = GetTextBounds();
var font = GetFont(); var font = GetFont();
SvgTextBase innerText; SvgTextBase innerText;
//RectangleF bounds; float x = (_x.Count < 1 ? _calcX : _x[0].ToDeviceValue(this)) + (_dx.Count < 1 ? 0 : _dx[0].ToDeviceValue(this));
float x = (_x == SvgUnit.Empty || _x == SvgUnit.None ? _calcX : _x.ToDeviceValue(this)) + _dx.ToDeviceValue(this); float y = (_y.Count < 1 ? _calcY : _y[0].ToDeviceValue(this, true)) + (_dy.Count < 1 ? 0 : _dy[0].ToDeviceValue(this, true));
float y = (_y == SvgUnit.Empty || _y == SvgUnit.None ? _calcY : _y.ToDeviceValue(this, true)) + _dy.ToDeviceValue(this, true);
_path = new GraphicsPath(); _path = new GraphicsPath();
_path.StartFigure(); _path.StartFigure();
// Measure the overall bounds of all the text
var boundsData = GetTextBounds();
// Determine the location of the start point // Determine the location of the start point
switch (this.TextAnchor) switch (this.TextAnchor)
{ {
...@@ -376,7 +386,7 @@ namespace Svg ...@@ -376,7 +386,7 @@ namespace Svg
{ {
innerText._calcX = x + data.xOffset; innerText._calcX = x + data.xOffset;
innerText._calcY = y + yCummOffset; innerText._calcY = y + yCummOffset;
yCummOffset += innerText.Dy.ToDeviceValue(this); if (innerText.Dy.Count == 1) yCummOffset += innerText.Dy[0].ToDeviceValue(this);
} }
} }
...@@ -486,7 +496,7 @@ namespace Svg ...@@ -486,7 +496,7 @@ namespace Svg
string[] words = (this.WordSpacing.Value > 0.0f) ? text.Split(' ') : new string[] { text }; string[] words = (this.WordSpacing.Value > 0.0f) ? text.Split(' ') : new string[] { text };
float wordSpacing = this.WordSpacing.ToDeviceValue(this); float wordSpacing = this.WordSpacing.ToDeviceValue(this);
float letterSpacing = this.LetterSpacing.ToDeviceValue(this); float letterSpacing = this.LetterSpacing.ToDeviceValue(this);
float start = this.X.ToDeviceValue(this); float start = x;
foreach (string word in words) foreach (string word in words)
{ {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment