Font changes, Text (harfbuzz) and sample project added
This commit is contained in:
BIN
samples/TextRendering/Assets/amiri-regular.ttf
Executable file
BIN
samples/TextRendering/Assets/amiri-regular.ttf
Executable file
Binary file not shown.
BIN
samples/TextRendering/Assets/fireflysung.ttf
Executable file
BIN
samples/TextRendering/Assets/fireflysung.ttf
Executable file
Binary file not shown.
54
samples/TextRendering/Assets/lime.svg
Normal file
54
samples/TextRendering/Assets/lime.svg
Normal file
@@ -0,0 +1,54 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Generator: Adobe Illustrator 17.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" [
|
||||
<!ENTITY ns_extend "http://ns.adobe.com/Extensibility/1.0/">
|
||||
<!ENTITY ns_ai "http://ns.adobe.com/AdobeIllustrator/10.0/">
|
||||
<!ENTITY ns_graphs "http://ns.adobe.com/Graphs/1.0/">
|
||||
<!ENTITY ns_vars "http://ns.adobe.com/Variables/1.0/">
|
||||
<!ENTITY ns_imrep "http://ns.adobe.com/ImageReplacement/1.0/">
|
||||
<!ENTITY ns_sfw "http://ns.adobe.com/SaveForWeb/1.0/">
|
||||
<!ENTITY ns_custom "http://ns.adobe.com/GenericCustomNamespace/1.0/">
|
||||
<!ENTITY ns_adobe_xpath "http://ns.adobe.com/XPath/1.0/">
|
||||
]>
|
||||
<svg version="1.1" xmlns:x="&ns_extend;" xmlns:i="&ns_ai;" xmlns:graph="&ns_graphs;"
|
||||
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="1371.6px"
|
||||
height="1371.6px" viewBox="0 0 1371.6 1371.6" enable-background="new 0 0 1371.6 1371.6" xml:space="preserve">
|
||||
<metadata>
|
||||
<sfw xmlns="&ns_sfw;">
|
||||
<slices></slices>
|
||||
<sliceSourceBounds width="1079.91" height="1367.408" bottomLeftOrigin="true" x="-234.016" y="-286.092"></sliceSourceBounds>
|
||||
</sfw>
|
||||
</metadata>
|
||||
<g id="Shape_19_1_" enable-background="new ">
|
||||
<g id="Shape_19">
|
||||
<g>
|
||||
<polygon fill-rule="evenodd" clip-rule="evenodd" fill="#8C9C42" points="1195.316,936.171 1190.961,422.366 711.929,152.4
|
||||
711.929,56.606 176.284,409.303 184.994,962.297 646.607,1227.909 646.607,1310.64 "/>
|
||||
</g>
|
||||
<g>
|
||||
<polygon fill="none" stroke="#71AD1B" stroke-width="60.4839" stroke-miterlimit="100" points="1195.316,936.171
|
||||
1190.961,422.366 711.929,152.4 711.929,56.606 176.284,409.303 184.994,962.297 646.607,1227.909 646.607,1310.64 "/>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
<g id="Shape_18_copy_1_" opacity="0.502" enable-background="new ">
|
||||
<g id="Shape_18_copy">
|
||||
<g>
|
||||
<polygon fill-rule="evenodd" clip-rule="evenodd" fill="#FFFFFF" points="703.219,683.623 698.155,695.438 698.865,182.88
|
||||
664.026,148.046 663.338,680.291 212.916,938 230.336,968.167 685.8,705.394 684.814,703.093 694.922,702.98 690.155,714.103
|
||||
1143.058,949.234 1164.832,923.109 "/>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
<g id="Shape_20_copy_1_" enable-background="new ">
|
||||
<g id="Shape_20_copy">
|
||||
<g>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" fill="#FFFFFF" d="M1172.718,936.171h0.824l2.218-498.411l-7.035-4.166
|
||||
l0.189-0.341l-470.05-273.635V91.44L250.903,386.114l-57.2,31.898l4.355,531.223l1.297-0.324l-1.348,2.316l466.018,271.956
|
||||
v61.332l501.303-341.361l8.505-5.133L1172.718,936.171z M665.741,194.562l447.104,247.473L684.288,675.308L244.653,428.044
|
||||
L665.741,194.562z M698.865,707.025l439.818-239.87l0.02,451.38l-439.838,265.454V707.025z M232.897,931.221V461.399
|
||||
l431.129,242.479v478.15L232.897,931.221z"/>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 2.8 KiB |
187
samples/TextRendering/Source/Main.hx
Normal file
187
samples/TextRendering/Source/Main.hx
Normal file
@@ -0,0 +1,187 @@
|
||||
package;
|
||||
|
||||
|
||||
import lime.app.Application;
|
||||
import lime.utils.Matrix4;
|
||||
import lime.graphics.*;
|
||||
import lime.graphics.opengl.*;
|
||||
import lime.utils.*;
|
||||
|
||||
|
||||
class Main extends Application {
|
||||
|
||||
|
||||
private var buffer:GLBuffer;
|
||||
private var matrixUniform:GLUniformLocation;
|
||||
private var program:GLProgram;
|
||||
private var texture:GLTexture;
|
||||
private var textureAttribute:Int;
|
||||
private var vertexAttribute:Int;
|
||||
|
||||
|
||||
public function new () {
|
||||
|
||||
super ();
|
||||
|
||||
}
|
||||
|
||||
|
||||
public override function init (context:RenderContext):Void {
|
||||
|
||||
var text:Text;
|
||||
var font = new Font ("assets/amiri-regular.ttf");
|
||||
|
||||
text = new Text (RightToLeft, ScriptArabic, "ar");
|
||||
text.fromString (font, "صِف خَلقَ خَودِ كَمِثلِ الشَمسِ إِذ بَزَغَت — يَحظى الضَجيعُ بِها نَجلاءَ مِعطارِ");
|
||||
var data = font.loadGlyphData (16, "صِفخَلقخودكَمثلالشمسإذبَزَغت—يحظىالضَجيعُبهانَلاءَمِعطار ");
|
||||
var image = data.image;
|
||||
|
||||
text = new Text (LeftToRight, ScriptLatin, "en");
|
||||
var data = font.loadGlyphData (32, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.");
|
||||
text.fromString (font, "The quick brown fox jumps over the lazy dog.");
|
||||
|
||||
font = new Font ("assets/fireflysung.ttf");
|
||||
text = new Text (TopToBottom, ScriptHan, "ch");
|
||||
text.fromString (font, "懶惰的姜貓");
|
||||
|
||||
var chinese = font.loadGlyphData (64, "懶惰的姜貓");
|
||||
|
||||
switch (context) {
|
||||
|
||||
case CANVAS (context):
|
||||
|
||||
context.fillStyle = "#" + StringTools.hex (config.background, 6);
|
||||
context.fillRect (0, 0, window.width, window.height);
|
||||
context.drawImage (image.src, 0, 0, image.width, image.height);
|
||||
|
||||
case DOM (element):
|
||||
|
||||
#if js
|
||||
element.style.backgroundColor = "#" + StringTools.hex (config.background, 6);
|
||||
element.appendChild (image);
|
||||
#end
|
||||
|
||||
case FLASH (sprite):
|
||||
|
||||
#if flash
|
||||
var bitmap = new flash.display.Bitmap (image.src);
|
||||
sprite.addChild (bitmap);
|
||||
#end
|
||||
|
||||
case OPENGL (gl):
|
||||
|
||||
var vertexSource =
|
||||
|
||||
"attribute vec4 aPosition;
|
||||
attribute vec2 aTexCoord;
|
||||
varying vec2 vTexCoord;
|
||||
|
||||
uniform mat4 uMatrix;
|
||||
|
||||
void main(void) {
|
||||
|
||||
vTexCoord = aTexCoord;
|
||||
gl_Position = uMatrix * aPosition;
|
||||
|
||||
}";
|
||||
|
||||
var fragmentSource =
|
||||
|
||||
"#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
varying vec2 vTexCoord;
|
||||
uniform sampler2D uImage0;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
gl_FragColor = vec4 (0, 0, 0, texture2D (uImage0, vTexCoord).a);
|
||||
}";
|
||||
|
||||
program = GLUtils.createProgram (vertexSource, fragmentSource);
|
||||
gl.useProgram (program);
|
||||
|
||||
vertexAttribute = gl.getAttribLocation (program, "aPosition");
|
||||
textureAttribute = gl.getAttribLocation (program, "aTexCoord");
|
||||
matrixUniform = gl.getUniformLocation (program, "uMatrix");
|
||||
var imageUniform = gl.getUniformLocation (program, "uImage0");
|
||||
|
||||
gl.enableVertexAttribArray (vertexAttribute);
|
||||
gl.enableVertexAttribArray (textureAttribute);
|
||||
gl.uniform1i (imageUniform, 0);
|
||||
|
||||
var data = [
|
||||
|
||||
image.width, image.height, 0, 1, 1,
|
||||
0, image.height, 0, 0, 1,
|
||||
image.width, 0, 0, 1, 0,
|
||||
0, 0, 0, 0, 0
|
||||
|
||||
];
|
||||
|
||||
buffer = gl.createBuffer ();
|
||||
gl.bindBuffer (gl.ARRAY_BUFFER, buffer);
|
||||
gl.bufferData (gl.ARRAY_BUFFER, new Float32Array (cast data), gl.STATIC_DRAW);
|
||||
gl.bindBuffer (gl.ARRAY_BUFFER, null);
|
||||
|
||||
#if desktop
|
||||
gl.enable (gl.TEXTURE_2D);
|
||||
#end
|
||||
|
||||
var format = image.bpp == 1 ? GL.ALPHA : GL.RGBA;
|
||||
texture = gl.createTexture ();
|
||||
gl.bindTexture (gl.TEXTURE_2D, texture);
|
||||
#if js
|
||||
gl.texImage2D (gl.TEXTURE_2D, 0, format, format, gl.UNSIGNED_BYTE, image.src);
|
||||
#else
|
||||
gl.texImage2D (gl.TEXTURE_2D, 0, format, image.textureWidth, image.textureHeight, 0, format, gl.UNSIGNED_BYTE, image.data);
|
||||
#end
|
||||
gl.texParameteri (gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
||||
gl.texParameteri (gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
||||
|
||||
gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
|
||||
gl.enable(gl.BLEND);
|
||||
|
||||
gl.viewport (0, 0, window.width, window.height);
|
||||
|
||||
default:
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public override function render (context:RenderContext):Void {
|
||||
|
||||
switch (context) {
|
||||
|
||||
case OPENGL (gl):
|
||||
|
||||
var r = ((config.background >> 16) & 0xFF) / 0xFF;
|
||||
var g = ((config.background >> 8) & 0xFF) / 0xFF;
|
||||
var b = (config.background & 0xFF) / 0xFF;
|
||||
var a = ((config.background >> 24) & 0xFF) / 0xFF;
|
||||
|
||||
gl.clearColor (r, g, b, a);
|
||||
gl.clear (gl.COLOR_BUFFER_BIT);
|
||||
|
||||
var matrix = Matrix4.createOrtho (0, window.width, window.height, 0, -10, 10);
|
||||
gl.uniformMatrix4fv (matrixUniform, false, matrix);
|
||||
|
||||
gl.activeTexture (gl.TEXTURE0);
|
||||
gl.bindTexture (gl.TEXTURE_2D, texture);
|
||||
|
||||
gl.bindBuffer (gl.ARRAY_BUFFER, buffer);
|
||||
gl.vertexAttribPointer (vertexAttribute, 3, gl.FLOAT, false, 5 * Float32Array.BYTES_PER_ELEMENT, 0);
|
||||
gl.vertexAttribPointer (textureAttribute, 2, gl.FLOAT, false, 5 * Float32Array.BYTES_PER_ELEMENT, 3 * Float32Array.BYTES_PER_ELEMENT);
|
||||
|
||||
gl.drawArrays (gl.TRIANGLE_STRIP, 0, 4);
|
||||
|
||||
default:
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
14
samples/TextRendering/project.xml
Normal file
14
samples/TextRendering/project.xml
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project>
|
||||
|
||||
<meta title="TextRendering" package="com.example.textrender" version="1.0.0" company="Company Name" />
|
||||
<app main="Main" path="Export" file="TextRendering" />
|
||||
|
||||
<source path="Source" />
|
||||
|
||||
<haxelib name="lime" />
|
||||
|
||||
<assets path="Assets" rename="assets" exclude="lime.svg" />
|
||||
<icon path="Assets/lime.svg" />
|
||||
|
||||
</project>
|
||||
Reference in New Issue
Block a user