mirror of
https://github.com/rive-app/rive-flutter.git
synced 2025-08-06 16:40:27 +08:00
Updating for latest shape results.
This commit is contained in:
@ -86,9 +86,7 @@ Future<void> renderFontDemo() async {
|
|||||||
// run.xAt(index)
|
// run.xAt(index)
|
||||||
}
|
}
|
||||||
glyphRuns.dispose();
|
glyphRuns.dispose();
|
||||||
// var glyph = roboto.getPath(222);
|
montserrat.dispose();
|
||||||
// glyph.issueCommands(paintGlyphPath);
|
|
||||||
// glyph.dispose();
|
|
||||||
roboto.dispose();
|
roboto.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,19 +28,19 @@ class GlyphPathStruct extends Struct {
|
|||||||
external int verbCount;
|
external int verbCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
class DynamicUint16Array extends Struct {
|
class SimpleUint16Array extends Struct {
|
||||||
external Pointer<Uint16> data;
|
external Pointer<Uint16> data;
|
||||||
@Uint64()
|
@Uint64()
|
||||||
external int size;
|
external int size;
|
||||||
}
|
}
|
||||||
|
|
||||||
class DynamicUint32Array extends Struct {
|
class SimpleUint32Array extends Struct {
|
||||||
external Pointer<Uint32> data;
|
external Pointer<Uint32> data;
|
||||||
@Uint64()
|
@Uint64()
|
||||||
external int size;
|
external int size;
|
||||||
}
|
}
|
||||||
|
|
||||||
class DynamicFloatArray extends Struct {
|
class SimpleFloatArray extends Struct {
|
||||||
external Pointer<Float> data;
|
external Pointer<Float> data;
|
||||||
@Uint64()
|
@Uint64()
|
||||||
external int size;
|
external int size;
|
||||||
@ -59,9 +59,10 @@ class RenderGlyphRunNative extends Struct implements RenderGlyphRun {
|
|||||||
@Float()
|
@Float()
|
||||||
external double size;
|
external double size;
|
||||||
|
|
||||||
external DynamicUint16Array glyphs;
|
external SimpleUint16Array glyphs;
|
||||||
external DynamicUint32Array textOffsets;
|
external SimpleUint32Array textOffsets;
|
||||||
external DynamicFloatArray xpos;
|
external SimpleFloatArray xpos;
|
||||||
|
external SimpleUint32Array breaks;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
double get fontSize => size;
|
double get fontSize => size;
|
||||||
|
@ -13,6 +13,7 @@ late js.JsFunction _deleteRenderFont;
|
|||||||
late js.JsFunction _makeGlyphPath;
|
late js.JsFunction _makeGlyphPath;
|
||||||
late js.JsFunction _deleteGlyphPath;
|
late js.JsFunction _deleteGlyphPath;
|
||||||
late js.JsFunction _shapeText;
|
late js.JsFunction _shapeText;
|
||||||
|
late js.JsFunction _deleteShapeResult;
|
||||||
|
|
||||||
class RawPathWasm extends RawPath {
|
class RawPathWasm extends RawPath {
|
||||||
final int rawPathPtr;
|
final int rawPathPtr;
|
||||||
@ -129,11 +130,12 @@ class RawPathIterator extends Iterator<RawPathCommand> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class TextShapeResultWasm extends TextShapeResult {
|
class TextShapeResultWasm extends TextShapeResult {
|
||||||
|
final int rawPathResultsPtr;
|
||||||
final List<RenderGlyphRun> runs;
|
final List<RenderGlyphRun> runs;
|
||||||
|
|
||||||
TextShapeResultWasm(this.runs);
|
TextShapeResultWasm(this.rawPathResultsPtr, this.runs);
|
||||||
@override
|
@override
|
||||||
void dispose() {}
|
void dispose() => _deleteShapeResult.apply(<dynamic>[rawPathResultsPtr]);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
RenderGlyphRun runAt(int index) => runs[index];
|
RenderGlyphRun runAt(int index) => runs[index];
|
||||||
@ -167,11 +169,13 @@ class RenderGlyphRunWasm extends RenderGlyphRun {
|
|||||||
final WasmDynamicArray glyphs;
|
final WasmDynamicArray glyphs;
|
||||||
final WasmDynamicArray textOffsets;
|
final WasmDynamicArray textOffsets;
|
||||||
final WasmDynamicArray xPositions;
|
final WasmDynamicArray xPositions;
|
||||||
|
final WasmDynamicArray breaks;
|
||||||
|
|
||||||
RenderGlyphRunWasm(this.byteData)
|
RenderGlyphRunWasm(this.byteData)
|
||||||
: glyphs = byteData.readDynamicArray(8),
|
: glyphs = byteData.readDynamicArray(8),
|
||||||
textOffsets = byteData.readDynamicArray(16),
|
textOffsets = byteData.readDynamicArray(16),
|
||||||
xPositions = byteData.readDynamicArray(24);
|
xPositions = byteData.readDynamicArray(24),
|
||||||
|
breaks = byteData.readDynamicArray(32);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
double get fontSize => byteData.getFloat32(4, Endian.little);
|
double get fontSize => byteData.getFloat32(4, Endian.little);
|
||||||
@ -237,30 +241,23 @@ class RenderFontWasm extends RenderFont {
|
|||||||
Uint32List.fromList(text.codeUnits),
|
Uint32List.fromList(text.codeUnits),
|
||||||
writer.uint8Buffer,
|
writer.uint8Buffer,
|
||||||
],
|
],
|
||||||
) as Uint8List;
|
) as js.JsObject;
|
||||||
|
|
||||||
var reader = BinaryReader.fromList(result);
|
var rawResult = result['rawResult'] as int;
|
||||||
|
var results = result['results'] as Uint8List;
|
||||||
|
|
||||||
|
var reader = BinaryReader.fromList(results);
|
||||||
var dataPointer = reader.readUint32();
|
var dataPointer = reader.readUint32();
|
||||||
var dataSize = reader.readUint32();
|
var dataSize = reader.readUint32();
|
||||||
print("RUN COUNTe ${dataSize}");
|
|
||||||
var runList = <RenderGlyphRunWasm>[];
|
var runList = <RenderGlyphRunWasm>[];
|
||||||
for (int i = 0; i < dataSize; i++) {
|
for (int i = 0; i < dataSize; i++) {
|
||||||
// var data = ByteData.view(result.buffer, dataPointer);
|
|
||||||
// var fontSizeOfRun = data.getFloat32(4, Endian.little);
|
|
||||||
// print("RFS $fontSizeOfRun");
|
|
||||||
runList
|
runList
|
||||||
.add(RenderGlyphRunWasm(ByteData.view(result.buffer, dataPointer)));
|
.add(RenderGlyphRunWasm(ByteData.view(results.buffer, dataPointer)));
|
||||||
// print("FONT SIZE: ${run.fontSize}");
|
dataPointer += 4 + 4 + 8 + 8 + 8 + 8;
|
||||||
dataPointer += 4 + 4 + 8 + 8 + 8;
|
|
||||||
}
|
}
|
||||||
// var view = ByteData.view(
|
|
||||||
// result.buffer, result.offsetInBytes, result.lengthInBytes);
|
|
||||||
// // size_t is 32 bit (4 bytes) in wasm
|
|
||||||
// var resultRunCount = view.getUint32(4, Endian.little);
|
|
||||||
// var resultRunCount = view.getUint32(4, Endian.little);
|
|
||||||
// for (int i = 0; i < resultRunCount; i++) {}
|
|
||||||
|
|
||||||
return TextShapeResultWasm(runList);
|
return TextShapeResultWasm(rawResult, runList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -303,6 +300,7 @@ Future<void> initRenderFont() async {
|
|||||||
_makeGlyphPath = module['makeGlyphPath'] as js.JsFunction;
|
_makeGlyphPath = module['makeGlyphPath'] as js.JsFunction;
|
||||||
_deleteGlyphPath = module['deleteGlyphPath'] as js.JsFunction;
|
_deleteGlyphPath = module['deleteGlyphPath'] as js.JsFunction;
|
||||||
_shapeText = module['shapeText'] as js.JsFunction;
|
_shapeText = module['shapeText'] as js.JsFunction;
|
||||||
|
_deleteShapeResult = module['deleteShapeResult'] as js.JsFunction;
|
||||||
completer.complete();
|
completer.complete();
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
@ -44,6 +44,9 @@ RenderFont["onRuntimeInitialized"] = function () {
|
|||||||
var nativeShapeText = RenderFont["shapeText"];
|
var nativeShapeText = RenderFont["shapeText"];
|
||||||
RenderFont["shapeText"] = function (codeUnits, runsList) {
|
RenderFont["shapeText"] = function (codeUnits, runsList) {
|
||||||
var shapeResult = nativeShapeText(codeUnits, runsList);
|
var shapeResult = nativeShapeText(codeUnits, runsList);
|
||||||
return HEAPU8["subarray"](shapeResult);
|
return {
|
||||||
|
"rawResult": shapeResult,
|
||||||
|
"results": HEAPU8["subarray"](shapeResult),
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -103,7 +103,6 @@ linkoptions {
|
|||||||
'--closure 1',
|
'--closure 1',
|
||||||
'--closure-args="--externs ./js/externs.js"',
|
'--closure-args="--externs ./js/externs.js"',
|
||||||
'--bind',
|
'--bind',
|
||||||
'-s ASSERTIONS=0',
|
|
||||||
'-s FORCE_FILESYSTEM=0',
|
'-s FORCE_FILESYSTEM=0',
|
||||||
'-s MODULARIZE=1',
|
'-s MODULARIZE=1',
|
||||||
'-s NO_EXIT_RUNTIME=1',
|
'-s NO_EXIT_RUNTIME=1',
|
||||||
@ -125,28 +124,40 @@ linkoptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
filter {'options:single_file'}
|
filter {'options:single_file'}
|
||||||
|
do
|
||||||
linkoptions {
|
linkoptions {
|
||||||
'-o %{cfg.targetdir}/render_font_single.js'
|
'-o %{cfg.targetdir}/render_font_single.js'
|
||||||
}
|
}
|
||||||
|
end
|
||||||
|
|
||||||
filter {'options:not single_file'}
|
filter {'options:not single_file'}
|
||||||
|
do
|
||||||
linkoptions {
|
linkoptions {
|
||||||
'-o %{cfg.targetdir}/render_font.js'
|
'-o %{cfg.targetdir}/render_font.js'
|
||||||
}
|
}
|
||||||
|
end
|
||||||
|
|
||||||
filter 'options:single_file'
|
filter 'options:single_file'
|
||||||
|
do
|
||||||
linkoptions {
|
linkoptions {
|
||||||
'-s SINGLE_FILE=1'
|
'-s SINGLE_FILE=1'
|
||||||
}
|
}
|
||||||
|
end
|
||||||
|
|
||||||
filter 'configurations:debug'
|
filter 'configurations:debug'
|
||||||
|
do
|
||||||
defines {'DEBUG'}
|
defines {'DEBUG'}
|
||||||
symbols 'On'
|
symbols 'On'
|
||||||
|
linkoptions {'-s ASSERTIONS=1'}
|
||||||
|
end
|
||||||
|
|
||||||
filter 'configurations:release'
|
filter 'configurations:release'
|
||||||
|
do
|
||||||
defines {'RELEASE'}
|
defines {'RELEASE'}
|
||||||
defines {'NDEBUG'}
|
defines {'NDEBUG'}
|
||||||
optimize 'On'
|
optimize 'On'
|
||||||
|
linkoptions {'-s ASSERTIONS=0'}
|
||||||
|
end
|
||||||
|
|
||||||
buildoptions {
|
buildoptions {
|
||||||
'-Oz',
|
'-Oz',
|
||||||
|
@ -27,7 +27,7 @@ WasmPtr makeRenderFont(emscripten::val byteArray) {
|
|||||||
return (WasmPtr) nullptr;
|
return (WasmPtr) nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void deleteRenderFont(WasmPtr renderFont) { delete reinterpret_cast<HBRenderFont*>(renderFont); }
|
void deleteRenderFont(WasmPtr renderFont) { reinterpret_cast<HBRenderFont*>(renderFont)->unref(); }
|
||||||
|
|
||||||
struct GlyphPath {
|
struct GlyphPath {
|
||||||
WasmPtr rawPath;
|
WasmPtr rawPath;
|
||||||
@ -50,6 +50,10 @@ GlyphPath makeGlyphPath(WasmPtr renderFontPtr, rive::GlyphID id) {
|
|||||||
|
|
||||||
void deleteGlyphPath(WasmPtr rawPath) { delete reinterpret_cast<rive::RawPath*>(rawPath); }
|
void deleteGlyphPath(WasmPtr rawPath) { delete reinterpret_cast<rive::RawPath*>(rawPath); }
|
||||||
|
|
||||||
|
void deleteShapeResult(WasmPtr shaperResult) {
|
||||||
|
delete reinterpret_cast<rive::SimpleArray<rive::RenderGlyphRun>*>(shaperResult);
|
||||||
|
}
|
||||||
|
|
||||||
WasmPtr shapeText(emscripten::val codeUnits, emscripten::val runsList) {
|
WasmPtr shapeText(emscripten::val codeUnits, emscripten::val runsList) {
|
||||||
std::vector<uint8_t> runsBytes(runsList["byteLength"].as<unsigned>());
|
std::vector<uint8_t> runsBytes(runsList["byteLength"].as<unsigned>());
|
||||||
{
|
{
|
||||||
@ -88,4 +92,5 @@ EMSCRIPTEN_BINDINGS(RenderFont) {
|
|||||||
function("deleteGlyphPath", &deleteGlyphPath);
|
function("deleteGlyphPath", &deleteGlyphPath);
|
||||||
|
|
||||||
function("shapeText", &shapeText);
|
function("shapeText", &shapeText);
|
||||||
|
function("deleteShapeResult", &deleteShapeResult);
|
||||||
}
|
}
|
Reference in New Issue
Block a user