mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-07-20 03:08:28 +08:00
Fix for shaper
This commit is contained in:
@ -66,6 +66,29 @@ AscFonts.CopyStreamToMemory = function(data, size)
|
||||
return fontStreamPointer;
|
||||
};
|
||||
|
||||
function CShapeString(size)
|
||||
{
|
||||
this.size = size;
|
||||
this.pointer = Module["_malloc"](size);
|
||||
}
|
||||
CShapeString.prototype.getBuffer = function()
|
||||
{
|
||||
return new Uint8Array(Module["HEAPU8"].buffer, this.pointer, this.size);
|
||||
};
|
||||
CShapeString.prototype.free = function()
|
||||
{
|
||||
Module["_free"](this.pointer);
|
||||
};
|
||||
CShapeString.prototype.set = function(index, value)
|
||||
{
|
||||
Module["HEAPU8"][this.pointer + index] = value;
|
||||
};
|
||||
|
||||
AscFonts.AllocString = function(size)
|
||||
{
|
||||
return new CShapeString(size);
|
||||
};
|
||||
|
||||
AscFonts.FT_CreateLibrary = Module["_ASC_FT_Init"];
|
||||
AscFonts.FT_Done_Library = Module["_ASC_FT_Done_FreeType"];
|
||||
AscFonts.FT_Set_TrueType_HintProp = Module["_ASC_FT_Set_TrueType_HintProp"];
|
||||
@ -149,7 +172,7 @@ AscFonts.HB_ShapeText = function(fontFile, text, features, script, direction, la
|
||||
Module["_free"](langPointer);
|
||||
}
|
||||
|
||||
let pointer = Module["_ASC_HP_ShapeText"](fontFile["GetFace"](), fontFile["GetHBFont"](), text, features, script, direction, hb_cache_languages[language]);
|
||||
let pointer = Module["_ASC_HB_ShapeText"](fontFile["GetFace"](), fontFile["GetHBFont"](), text.pointer, features, script, direction, hb_cache_languages[language]);
|
||||
if (!pointer)
|
||||
{
|
||||
g_return_obj_count.error = 1;
|
||||
|
||||
@ -54,6 +54,29 @@ AscFonts.CopyStreamToMemory = function(data, size)
|
||||
return data;
|
||||
};
|
||||
|
||||
function CShapeString(size)
|
||||
{
|
||||
this.size = size;
|
||||
this.pointer = new Uint8Array(size);
|
||||
}
|
||||
CShapeString.prototype.getBuffer = function()
|
||||
{
|
||||
return this.pointer;
|
||||
};
|
||||
CShapeString.prototype.free = function()
|
||||
{
|
||||
// GC
|
||||
};
|
||||
CShapeString.prototype.set = function(index, value)
|
||||
{
|
||||
this.pointer[index] = value;
|
||||
};
|
||||
|
||||
AscFonts.AllocString = function(size)
|
||||
{
|
||||
return new CShapeString(size);
|
||||
};
|
||||
|
||||
AscFonts.FT_CreateLibrary = function(library)
|
||||
{
|
||||
return g_native_engine["FT_Init"](library);
|
||||
@ -167,7 +190,7 @@ AscFonts.HB_ShapeText = function(fontFile, text, features, script, direction, la
|
||||
if (!fontFile["GetHBFont"]())
|
||||
fontFile["SetHBFont"](g_native_engine["FT_Malloc"](0));
|
||||
|
||||
let data = g_native_engine["HB_ShapeText"](fontFile["GetFace"](), fontFile["GetHBFont"](), text, features, script, direction, hb_cache_languages[language]);
|
||||
let data = g_native_engine["HB_ShapeText"](fontFile["GetFace"](), fontFile["GetHBFont"](), text.pointer, features, script, direction, hb_cache_languages[language]);
|
||||
if (!data)
|
||||
{
|
||||
g_return_obj_count.error = 1;
|
||||
|
||||
@ -40,6 +40,17 @@ function onLoadFontsModule(window, undefined)
|
||||
|
||||
AscFonts.CopyStreamToMemory = AscFonts["CopyStreamToMemory"];
|
||||
|
||||
AscFonts.AllocString2 = AscFonts["AllocString"];
|
||||
AscFonts.AllocString = function(size)
|
||||
{
|
||||
var pointer = AscFonts.AllocString2(size);
|
||||
pointer.pointer = pointer["pointer"];
|
||||
pointer.getBuffer = pointer["getBuffer"];
|
||||
pointer.free = pointer["free"];
|
||||
pointer.set = pointer["set"];
|
||||
return pointer;
|
||||
};
|
||||
|
||||
AscFonts.FT_CreateLibrary = AscFonts["FT_CreateLibrary"];
|
||||
AscFonts.FT_Done_Library = AscFonts["FT_Done_Library"];
|
||||
AscFonts.FT_Set_TrueType_HintProp = AscFonts["FT_Set_TrueType_HintProp"];
|
||||
@ -441,7 +452,7 @@ function onLoadFontsModule(window, undefined)
|
||||
AscFonts.HB_StartString = function()
|
||||
{
|
||||
if (!STRING_POINTER)
|
||||
STRING_POINTER = Module.AllocString(6 * STRING_MAX_LEN + 1);
|
||||
STRING_POINTER = AscFonts.AllocString(6 * STRING_MAX_LEN + 1);
|
||||
|
||||
STRING_LEN = 0;
|
||||
CLUSTER_LEN = 0;
|
||||
@ -449,7 +460,7 @@ function onLoadFontsModule(window, undefined)
|
||||
};
|
||||
AscFonts.HB_AppendToString = function(code)
|
||||
{
|
||||
let arrBuffer = STRING_POINTER.buffer;
|
||||
let arrBuffer = STRING_POINTER.getBuffer();
|
||||
let nClusterLen = -1;
|
||||
|
||||
if (code < 0x80)
|
||||
@ -506,7 +517,7 @@ function onLoadFontsModule(window, undefined)
|
||||
};
|
||||
AscFonts.HB_EndString = function()
|
||||
{
|
||||
STRING_POINTER.buffer[STRING_LEN++] = 0;
|
||||
STRING_POINTER.set(STRING_LEN++, 0);
|
||||
};
|
||||
AscFonts.HB_GetStringLength = function()
|
||||
{
|
||||
@ -598,6 +609,7 @@ function onLoadFontsModule(window, undefined)
|
||||
let utf8_start = 0;
|
||||
let utf8_end = 0;
|
||||
|
||||
let arBuffer = STRING_POINTER.getBuffer();
|
||||
if (direction === AscFonts.HB_DIRECTION.HB_DIRECTION_RTL)
|
||||
{
|
||||
for (let i = glyphsCount - 1; i >= 0; i--)
|
||||
@ -607,7 +619,7 @@ function onLoadFontsModule(window, undefined)
|
||||
else
|
||||
utf8_end = glyphs[i - 1].cluster;
|
||||
|
||||
glyphs[i].text = String.prototype.fromUtf8(STRING_POINTER.buffer, utf8_start, utf8_end - utf8_start);
|
||||
glyphs[i].text = String.prototype.fromUtf8(arBuffer, utf8_start, utf8_end - utf8_start);
|
||||
utf8_start = utf8_end;
|
||||
}
|
||||
}
|
||||
@ -620,7 +632,7 @@ function onLoadFontsModule(window, undefined)
|
||||
else
|
||||
utf8_end = glyphs[i + 1].cluster;
|
||||
|
||||
glyphs[i].text = String.prototype.fromUtf8(STRING_POINTER.buffer, utf8_start, utf8_end - utf8_start);
|
||||
glyphs[i].text = String.prototype.fromUtf8(arBuffer, utf8_start, utf8_end - utf8_start);
|
||||
utf8_start = utf8_end;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user