Skip to content
This repository
Browse code

update

  • Loading branch information...
commit 53eb93bb71f726c7c863f3a4f5d90af6574a3c60 1 parent 6c381e4
Jonas Nyström authored

Showing 1 changed file with 37 additions and 13 deletions. Show diff stats Hide diff stats

  1. +37 13 src/Cx.hx
50 src/Cx.hx
... ... @@ -1,8 +1,3 @@
1   -import format.zip.Data;
2   -import format.zip.Tools;
3   -import haxe.io.Bytes;
4   -import haxe.xml.Fast;
5   -import neko.zip.Reader;
6 1 /**
7 2 * ...
8 3 * @author Jonas Nyström
@@ -29,14 +24,20 @@ class Cx {
29 24 f.close();
30 25 }
31 26
  27 + static public function putContentBinary(filename:String, content:String) {
  28 + var f = neko.io.File.write(filename, true);
  29 + f.writeString(content);
  30 + f.close();
  31 + }
  32 +
32 33 //-----------------------------------------------------------------------------------------------
33   -
  34 +
34 35 static public function pngToHtmlImg(pngFile:String) {
35 36 var bytes = neko.io.File.getBytes(pngFile);
36 37 return pngBytesToHtmlImg(bytes);
37 38 }
38 39
39   - static public function pngBytesToHtmlImg(pngBytes:Bytes, ?style:String='') {
  40 + static public function pngBytesToHtmlImg(pngBytes:haxe.io.Bytes, ?style:String='') {
40 41 var string = pngBytes.toString();
41 42 var BASE64:String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
42 43 var string64 = haxe.BaseCode.encode(string, BASE64);
@@ -61,7 +62,7 @@ class Cx {
61 62 }
62 63 }
63 64
64   - static public function zipGetEntryData(zipEntries: List<format.zip.Data.Entry>, entryFileName:String): Bytes {
  65 + static public function zipGetEntryData(zipEntries: List<format.zip.Data.Entry>, entryFileName:String): haxe.io.Bytes {
65 66 for (zipEntry in zipEntries ) {
66 67 if (zipEntry.fileName == entryFileName) {
67 68 return zipEntry.data;
@@ -72,13 +73,13 @@ class Cx {
72 73
73 74 //----------------------------------------------------------------------------------------------------------
74 75
75   - /*
76   - var html = Cx.odtContentGetMeta() + Cx.odtToHtml('5a.odt');
77   - Cx.putContent('odt2.html', html);
78   - */
  76 + static public function odtTest(odtFileName:String) {
  77 + var html = Cx.odtContentGetMeta() + Cx.odtToHtml(odtFileName);
  78 + Cx.putContent(odtFileName+'.html', html);
  79 + }
79 80
80 81 static public function odtGetContentXmlStr(zipEntries:List<format.zip.Data.Entry>):String {
81   - var contentBytes:Bytes = zipGetEntryData(zipEntries, 'content.xml');
  82 + var contentBytes:haxe.io.Bytes = zipGetEntryData(zipEntries, 'content.xml');
82 83 var xmlStr = contentBytes.toString();
83 84 return xmlStr;
84 85 }
@@ -208,4 +209,27 @@ class Cx {
208 209 recursive(xml);
209 210 return html;
210 211 }
  212 +
  213 + //--------------------------------------------------------------------------------------------------------
  214 +
  215 + static public function nmeSpriteToPngTest() {
  216 + var sprite = new nme.display.Sprite();
  217 + sprite.graphics.beginFill(0x0000FF);
  218 + sprite.graphics.drawCircle(20, 10, 8);
  219 + sprite.graphics.drawCircle(220, 210, 8);
  220 + Cx.nmeSpriteToPng(sprite, 'nmeSprite.png');
  221 + }
  222 +
  223 + static public function nmeSpriteToPng(source : nme.display.Sprite, pngFileName:String, ?width=0.0, ?height=0.0) {
  224 + if (width == 0) {
  225 + width = source.width;
  226 + height = source.height;
  227 + }
  228 + var bitmapData = new nme.display.BitmapData(Std.int(width), Std.int(height), false);
  229 + bitmapData.draw(source);
  230 + var byteArray = bitmapData.encode('x');
  231 + putContentBinary(pngFileName, byteArray.asString());
  232 + }
  233 +
  234 +
211 235 }

0 comments on commit 53eb93b

Please sign in to comment.
Something went wrong with that request. Please try again.