Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified .gitignore
100644 → 100755
Empty file.
Empty file modified README.md
100644 → 100755
Empty file.
Empty file modified format/SVG.hx
100644 → 100755
Empty file.
31 changes: 31 additions & 0 deletions format/gfx/BitmapFill.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package format.gfx;

import flash.geom.ColorTransform;
import flash.geom.Rectangle;
import flash.geom.Matrix;
import flash.display.BitmapData;

class BitmapFill {
public function new() {
matrix = new Matrix();
}

public var bitmapData:BitmapData;
public var matrix: Matrix;
public var repeat: Bool = true;
public var smooth: Bool = false;
@:isVar
public var alpha(default, set): Float = 1;

private function set_alpha(value:Float):Float {
alpha = value;
if(bitmapData != null && value < 1) {
bitmapData.lock();
var rect: Rectangle = new Rectangle(0,0,bitmapData.width,bitmapData.height);
bitmapData.colorTransform(rect, new ColorTransform(1,1,1,alpha));
bitmapData.unlock(rect);
}
return alpha;
}
}

1 change: 1 addition & 0 deletions format/gfx/Gfx.hx
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Gfx
public function geometryOnly() { return false; }
public function size(inWidth:Float,inHeight:Float) { }
public function beginGradientFill(grad:Gradient) { }
public function beginBitmapFill(bitmap: BitmapFill) {}

public function beginFill(color:Int, alpha:Float) { }
public function endFill() { }
Expand Down
Empty file modified format/gfx/Gfx2Haxe.hx
100644 → 100755
Empty file.
14 changes: 7 additions & 7 deletions format/gfx/GfxBytes.hx
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class GfxBytes extends Gfx

case GRADIENT_FILL:
var grad = new Gradient();
grad.type = Type.createEnumIndex(GradientType,buffer.readByte());
grad.type = cast buffer.readByte();
var len = buffer.readByte();
for(i in 0...len)
{
Expand Down Expand Up @@ -208,7 +208,7 @@ class GfxBytes extends Gfx
override public function beginGradientFill(grad:Gradient)
{
buffer.writeByte(GRADIENT_FILL);
buffer.writeByte(Type.enumIndex(grad.type));
buffer.writeByte(cast grad.type);
buffer.writeByte(grad.colors.length);
for(i in 0...grad.colors.length)
{
Expand All @@ -222,8 +222,8 @@ class GfxBytes extends Gfx
buffer.writeFloat(grad.matrix.d);
buffer.writeFloat(grad.matrix.tx);
buffer.writeFloat(grad.matrix.ty);
buffer.writeByte(Type.enumIndex(grad.spread));
buffer.writeByte(Type.enumIndex(grad.interp));
buffer.writeByte(cast grad.spread);
buffer.writeByte(cast grad.interp);
buffer.writeFloat(grad.focus);
}

Expand All @@ -245,9 +245,9 @@ class GfxBytes extends Gfx
writeRGB(style.color);
buffer.writeFloat(style.alpha);
buffer.writeByte(style.pixelHinting?1:0);
buffer.writeByte(Type.enumIndex(style.scaleMode));
buffer.writeByte(Type.enumIndex(style.capsStyle));
buffer.writeByte(Type.enumIndex(style.jointStyle));
buffer.writeByte(cast style.scaleMode);
buffer.writeByte(cast style.capsStyle);
buffer.writeByte(cast style.jointStyle);
buffer.writeFloat(style.miterLimit);
}

Expand Down
Empty file modified format/gfx/GfxExtent.hx
100644 → 100755
Empty file.
5 changes: 5 additions & 0 deletions format/gfx/GfxGraphics.hx
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ class GfxGraphics extends Gfx
graphics.beginGradientFill(grad.type,grad.colors,grad.alphas,grad.ratios,grad.matrix,grad.spread,grad.interp,grad.focus);
}

override public function beginBitmapFill(fill:BitmapFill)
{
graphics.beginBitmapFill(fill.bitmapData, fill.matrix, fill.repeat, fill.smooth);
}

override public function beginFill(color:Int, alpha:Float) { graphics.beginFill(color,alpha); }
override public function endFill() { graphics.endFill(); }

Expand Down
Empty file modified format/gfx/GfxTextFinder.hx
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion format/gfx/Gradient.hx
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Gradient
}

public var type:GradientType;
public var colors:Array<Int>;
public var colors:Array<UInt>;
public var alphas:Array<Float>;
public var ratios:Array<Int>;
public var matrix: Matrix;
Expand Down
Empty file modified format/gfx/LineStyle.hx
100644 → 100755
Empty file.
31 changes: 13 additions & 18 deletions format/svg/BitmapDataManager.hx
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package format.svg;

//import gm2d.reso.Resources;
import format.svg.SvgRenderer;
//import format.svg.SVGRenderer;

import flash.display.DisplayObjectContainer;
import flash.geom.Matrix;
import flash.display.Shape;
import flash.display.Bitmap;
Expand All @@ -11,36 +12,30 @@ import flash.display.BitmapData;

class BitmapDataManager
{
static var bitmaps = new Hash<BitmapData>();
static var bitmaps = new Map<String, BitmapData>();
static var mScale = 0.0;

public static function create(inSVG:String, inGroup:String, inScale:Float, inCache=false)
{
var key = inSVG + " : " + inGroup + " : " +inScale;
if (bitmaps.exists(key))
return bitmaps.get(key);
if (bitmaps.exists(key)) {
return bitmaps.get(key);
}

//var svg:SvgRenderer = new SvgRenderer( Resources.loadSvg(inSVG) );
var svg = null;
return;


var shape = new Shape();
if (inGroup=="")
svg.RenderObject(shape,shape.graphics);
else
svg.RenderObject(shape,shape.graphics,null, function(_,groups) { return groups[0]==inGroup; });

svg = new SVG(inSVG);
svg.render(shape.graphics, 0, 0);

var matrix = new Matrix();
matrix.scale(inScale,inScale);

var w = Std.int(svg.width*inScale + 0.99);
var h = Std.int(svg.height*inScale + 0.99);
var w = Std.int(svg.data.width);
var h = Std.int(svg.data.height);
var bmp = new BitmapData(w,h,true,0x00);
var q = gm2d.Lib.current.stage.quality;
flash.Lib.current.stage.quality = flash.display.StageQuality.BEST;
bmp.draw(shape,matrix);
flash.Lib.current.stage.quality = q;

if (inCache)
bitmaps.set(key,bmp);
return bmp;
Expand All @@ -50,7 +45,7 @@ class BitmapDataManager
{
if (inScale!=mScale)
{
bitmaps = new Hash<BitmapData>();
bitmaps = new Map<String, BitmapData>();
mScale = inScale;
}
}
Expand Down
38 changes: 38 additions & 0 deletions format/svg/BitmapFill.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package format.svg;

import flash.geom.Matrix;
import flash.display.BitmapData;

class BitmapFill extends format.gfx.BitmapFill {
public var fillMatrix: Matrix;
public var x1:Float;
public var y1:Float;
public var x2:Float;
public var y2:Float;

public function new() {
super();
fillMatrix = new Matrix();
x1 = 0.0;
y1 = 0.0;
x2 = 0.0;
y2 = 0.0;
}

public function updateMatrix(inMatrix:Matrix)
{
var dx = x2 - x1;
var dy = y2 - y1;
var theta = Math.atan2(dy,dx);
var len = Math.sqrt(dx*dx+dy*dy);

var mtx = new Matrix();

mtx.rotate(theta);
mtx.translate(x1,y1);
mtx.concat(fillMatrix);
mtx.concat(inMatrix);
matrix = mtx;
}
}

1 change: 1 addition & 0 deletions format/svg/FillType.hx
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ enum FillType
{
FillGrad(grad:Grad);
FillSolid(colour:Int);
BitmapFill(fill: BitmapFill);
FillNone;
}

Empty file modified format/svg/Grad.hx
100644 → 100755
Empty file.
Empty file modified format/svg/Gradient.hx
100644 → 100755
Empty file.
Empty file modified format/svg/Group.hx
100644 → 100755
Empty file.
Empty file modified format/svg/Path.hx
100644 → 100755
Empty file.
52 changes: 26 additions & 26 deletions format/svg/PathParser.hx
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,33 @@ class PathParser {

static var sCommandArgs:Array<Int>;

static inline var MOVE = 77; //"M".charCodeAt(0);
static inline var MOVER = 109; //"m".charCodeAt(0);
static inline var LINE = 76; // "L".charCodeAt(0);
static inline var LINER = 108; // "l".charCodeAt(0);
static inline var HLINE = 72; // "H".charCodeAt(0);
static inline var HLINER = 104; // "h".charCodeAt(0);
static inline var VLINE = 86; // "V".charCodeAt(0);
static inline var VLINER = 118; // "v".charCodeAt(0);
static inline var CUBIC = 67; // "C".charCodeAt(0);
static inline var CUBICR = 99; // "c".charCodeAt(0);
static inline var SCUBIC = 83; // "S".charCodeAt(0);
static inline var SCUBICR = 115; // "s".charCodeAt(0);
static inline var QUAD = 81; // "Q".charCodeAt(0);
static inline var QUADR = 113; // "q".charCodeAt(0);
static inline var SQUAD = 84; // "T".charCodeAt(0);
static inline var SQUADR = 116; // "t".charCodeAt(0);
static inline var ARC = 65; // "A".charCodeAt(0);
static inline var ARCR = 97; // "a".charCodeAt(0);
static inline var CLOSE = 90; // "Z".charCodeAt(0);
static inline var CLOSER = 122; // "z".charCodeAt(0);
static inline var MOVE = "M".code;
static inline var MOVER = "m".code;
static inline var LINE = "L".code;
static inline var LINER = "l".code;
static inline var HLINE = "H".code;
static inline var HLINER = "h".code;
static inline var VLINE = "V".code;
static inline var VLINER = "v".code;
static inline var CUBIC = "C".code;
static inline var CUBICR = "c".code;
static inline var SCUBIC = "S".code;
static inline var SCUBICR = "s".code;
static inline var QUAD = "Q".code;
static inline var QUADR = "q".code;
static inline var SQUAD = "T".code;
static inline var SQUADR = "t".code;
static inline var ARC = "A".code;
static inline var ARCR = "a".code;
static inline var CLOSE = "Z".code;
static inline var CLOSER = "z".code;

static var UNKNOWN = -1;
static var SEPARATOR = -2;
static var FLOAT = -3;
static var FLOAT_SIGN = -4;
static var FLOAT_DOT = -5;
static var FLOAT_EXP = -6;
static inline var UNKNOWN = -1;
static inline var SEPARATOR = -2;
static inline var FLOAT = -3;
static inline var FLOAT_SIGN = -4;
static inline var FLOAT_DOT = -5;
static inline var FLOAT_EXP = -6;



Expand Down
Empty file modified format/svg/PathSegment.hx
100644 → 100755
Empty file.
Empty file modified format/svg/RenderContext.hx
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion format/svg/SVG2Gfx.hx
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Xml;

class SVG2Gfx
{
var renderer : SvgRenderer;
var renderer : SVGRenderer;

public function new (inXml:Xml)
{
Expand Down
Loading