Skip to content

Commit

Permalink
Refactor: Moving struct as inner.
Browse files Browse the repository at this point in the history
  • Loading branch information
vidstige committed Oct 17, 2016
1 parent eb0011a commit 4feeaeb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 39 deletions.
1 change: 0 additions & 1 deletion NOpenType/NOpenType.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Tables\TableEntry.cs" />
<Compile Include="Typeface.cs" />
<Compile Include="PathBuilderAdapter.cs" />
<Compile Include="IGlyphRasterizer.cs" />
<Compile Include="Rasterizer\Line.cs" />
<Compile Include="Rasterizer\Raster.cs" />
Expand Down
23 changes: 0 additions & 23 deletions NOpenType/PathBuilderAdapter.cs

This file was deleted.

41 changes: 26 additions & 15 deletions NOpenType/Renderer.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
//Apache2, 2014-2016, WinterDev
using System;
using FtPointD = NRasterizer.Point<double>;

namespace NRasterizer
{
public class Renderer
{
private struct Point<T>
{
public readonly T x;
public readonly T y;

public Point(T x, T y)
{
this.x = x;
this.y = y;
}

public T X { get { return x; } }
public T Y { get { return y; } }
}

private readonly IGlyphRasterizer _rasterizer;
private readonly Typeface _typeface;
private const int pointsPerInch = 72;
Expand All @@ -26,14 +40,12 @@ void RenderGlyph(float x, float y, Glyph glyph)
short[] ys = glyph.Y;
bool[] onCurves = glyph.On;

//outline version
//-----------------------------
int npoints = xs.Length;
int startContour = 0;
int cpoint_index = 0;
//-----------------------------------

rasterizer.BeginRead(contours.Length);
//-----------------------------------

double lastMoveX = 0;
double lastMoveY = 0;

Expand All @@ -42,8 +54,8 @@ void RenderGlyph(float x, float y, Glyph glyph)
{
int nextContour = contours[startContour] + 1;
bool isFirstPoint = true;
FtPointD secondControlPoint = new FtPointD();
FtPointD thirdControlPoint = new FtPointD();
Point<double> secondControlPoint = new Point<double>();
Point<double> thirdControlPoint = new Point<double>();
bool justFromCurveMode = false;

for (; cpoint_index < nextContour; ++cpoint_index)
Expand Down Expand Up @@ -98,15 +110,15 @@ void RenderGlyph(float x, float y, Glyph glyph)
{
case 0:
{
secondControlPoint = new FtPointD(vpoint_x, vpoint_y);
secondControlPoint = new Point<double>(vpoint_x, vpoint_y);
}
break;
case 1:
{
//we already have prev second control point
//so auto calculate line to
//between 2 point
FtPointD mid = GetMidPoint(secondControlPoint, vpoint_x, vpoint_y);
Point<double> mid = GetMidPoint(secondControlPoint, vpoint_x, vpoint_y);
//----------
//generate curve3
rasterizer.Curve3(secondControlPoint.x / FT_RESIZE, secondControlPoint.y / FT_RESIZE,
Expand All @@ -115,14 +127,13 @@ void RenderGlyph(float x, float y, Glyph glyph)
controlPointCount--;
//------------------------
//printf("[%d] bzc2nd, x: %d,y:%d \n", mm, vpoint.x, vpoint.y);
secondControlPoint = new FtPointD(vpoint_x, vpoint_y);
secondControlPoint = new Point<double>(vpoint_x, vpoint_y);
}
break;
default:
{
throw new NotSupportedException("Too many control points");
}
break;
}

controlPointCount++;
Expand Down Expand Up @@ -163,16 +174,16 @@ void RenderGlyph(float x, float y, Glyph glyph)
_rasterizer.EndRead();
}

private static FtPointD GetMidPoint(FtPointD v1, int v2x, int v2y)
private static Point<double> GetMidPoint(Point<double> v1, int v2x, int v2y)
{
return new FtPointD(
return new Point<double>(
((double)v1.X + (double)v2x) / 2d,
((double)v1.Y + (double)v2y) / 2d);
}

private static FtPointD GetMidPoint(FtPointD v1, FtPointD v2)
private static Point<double> GetMidPoint(Point<double> v1, Point<double> v2)
{
return new FtPointD(
return new Point<double>(
((double)v1.x + (double)v2.x) / 2d,
((double)v1.y + (double)v2.y) / 2d);
}
Expand Down

0 comments on commit 4feeaeb

Please sign in to comment.