-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
216 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace NRasterizer | ||
{ | ||
public class CompositeGlyph: IGlyph | ||
{ | ||
public class Composite | ||
{ | ||
private readonly ushort _glyphIndex; | ||
private readonly Transform _transform; | ||
public Composite(ushort glyphIndex, Transform transform) | ||
{ | ||
_glyphIndex = glyphIndex; | ||
_transform = transform; | ||
} | ||
|
||
public ushort GlyphIndex { get { return _glyphIndex; } } | ||
public Transform Transform { get { return _transform; } } | ||
} | ||
|
||
private readonly List<Composite> _composites; | ||
|
||
public CompositeGlyph(List<Composite> composites) | ||
{ | ||
_composites = composites; | ||
} | ||
|
||
private IGlyph Transform(Transform transform, IGlyph glyph) | ||
{ | ||
return glyph; | ||
} | ||
|
||
private T[] Concat<T>(T[] first, T[] second) | ||
{ | ||
var result = new T[first.Length + second.Length]; | ||
first.CopyTo(result, 0); | ||
second.CopyTo(result, first.Length); | ||
return result; | ||
} | ||
|
||
private IGlyph Combine(IGlyph first, IGlyph second) | ||
{ | ||
var xs = Concat(first.X, second.X); | ||
var ys = Concat(first.Y, second.Y); | ||
var ons = Concat(first.On, second.On); | ||
|
||
var endPoints = (ushort[])second.EndPoints.Clone(); | ||
var offset = first.X.Length; | ||
for (int i = 0; i < endPoints.Length; i++) | ||
{ | ||
endPoints[i] = (ushort)(endPoints[i] + offset); | ||
} | ||
|
||
return new Glyph(xs, ys, ons, Concat(first.EndPoints, endPoints), null); | ||
} | ||
|
||
public IGlyph Flatten(List<IGlyph> glyphs) | ||
{ | ||
IGlyph flat = Glyph.Empty; | ||
List<IGlyph> parts = new List<IGlyph>(); | ||
foreach (var composite in _composites) | ||
{ | ||
flat = Combine(flat, Transform(composite.Transform, glyphs[composite.GlyphIndex])); | ||
parts.Add(glyphs[composite.GlyphIndex]); | ||
} | ||
|
||
return flat; | ||
} | ||
|
||
#region IGlyph implementation | ||
|
||
public Bounds Bounds { get { throw new NotSupportedException(); } } | ||
|
||
public short[] X { get { throw new NotSupportedException(); } } | ||
|
||
public short[] Y { get { throw new NotSupportedException(); } } | ||
|
||
public bool[] On { get { throw new NotSupportedException(); } } | ||
|
||
public ushort[] EndPoints { get { throw new NotSupportedException(); } } | ||
|
||
#endregion | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System; | ||
|
||
namespace NRasterizer | ||
{ | ||
public interface IGlyph | ||
{ | ||
Bounds Bounds { get; } | ||
|
||
short[] X { get; } | ||
short[] Y { get; } | ||
bool[] On { get; } | ||
ushort[] EndPoints { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
|
||
namespace NRasterizer | ||
{ | ||
public class Transform | ||
{ | ||
private readonly short _m00; | ||
private readonly short _m01; | ||
private readonly short _m10; | ||
private readonly short _m11; | ||
private readonly short _dx; | ||
private readonly short _dy; | ||
|
||
public Transform(short m00, short m01, short m10, short m11, short dx, short dy) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters