mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-26 01:11:25 +01:00
[gpu] Add font feature support to demo
- demo_buffer_set_features() sets global features for hb_shape
- web_set_features() wasm export parses comma-separated features
- Shell message handler accepts { kind: "features", value }
- Features applied to all shape calls in demo_buffer_add_text
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
fd0a18dcc2
commit
036a5ad86f
5 files changed
+44
-2
No files matched your search
+11
-1
@@ -5,6 +5,16 @@
|
||||
|
||||
#include "demo-buffer.h"
|
||||
|
||||
static hb_feature_t g_features[64];
|
||||
static unsigned g_feature_count = 0;
|
||||
|
||||
void
|
||||
demo_buffer_set_features (const hb_feature_t *features, unsigned count)
|
||||
{
|
||||
g_feature_count = count < 64 ? count : 64;
|
||||
memcpy (g_features, features, g_feature_count * sizeof (hb_feature_t));
|
||||
}
|
||||
|
||||
struct demo_buffer_t {
|
||||
demo_point_t cursor;
|
||||
std::vector<glyph_vertex_t> *vertices;
|
||||
@@ -84,7 +94,7 @@ demo_buffer_add_text (demo_buffer_t *buffer,
|
||||
hb_buffer_clear_contents (hb_buffer);
|
||||
hb_buffer_add_utf8 (hb_buffer, utf8, end ? end - utf8 : -1, 0, -1);
|
||||
hb_buffer_guess_segment_properties (hb_buffer);
|
||||
hb_shape (hb_font, hb_buffer, NULL, 0);
|
||||
hb_shape (hb_font, hb_buffer, g_features, g_feature_count);
|
||||
|
||||
unsigned count;
|
||||
hb_glyph_info_t *infos = hb_buffer_get_glyph_infos (hb_buffer, &count);
|
||||
|
||||
@@ -59,4 +59,7 @@ unsigned
|
||||
demo_buffer_get_generation (demo_buffer_t *buffer);
|
||||
|
||||
|
||||
void
|
||||
demo_buffer_set_features (const hb_feature_t *features, unsigned count);
|
||||
|
||||
#endif /* DEMO_BUFFER_H */
|
||||
@@ -30,7 +30,7 @@ em++ \
|
||||
-sUSE_WEBGL2=1 \
|
||||
-sFULL_ES3=1 \
|
||||
-sALLOW_MEMORY_GROWTH=1 \
|
||||
-sEXPORTED_FUNCTIONS='["_main","_web_load_font","_web_set_text","_web_get_text","_web_set_variations","_web_set_palette","_web_set_dark","_web_toggle_animation","_web_reset","_web_request_redraw","_web_cancel_gesture","_web_pinch","_malloc","_free"]' \
|
||||
-sEXPORTED_FUNCTIONS='["_main","_web_load_font","_web_set_text","_web_get_text","_web_set_variations","_web_set_features","_web_set_palette","_web_set_dark","_web_toggle_animation","_web_reset","_web_request_redraw","_web_cancel_gesture","_web_pinch","_malloc","_free"]' \
|
||||
-sEXPORTED_RUNTIME_METHODS='["UTF8ToString","lengthBytesUTF8","stringToUTF8"]' \
|
||||
--shell-file "$SRCDIR/util/gpu/web/shell.html" \
|
||||
-o "$OUTDIR/index.html"
|
||||
|
||||
@@ -146,6 +146,24 @@ web_set_variations (const char *settings)
|
||||
rebuild_buffer (custom_text ? current_text : default_text_en);
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void
|
||||
web_set_features (const char *settings)
|
||||
{
|
||||
hb_feature_t feats[64];
|
||||
unsigned n = 0;
|
||||
const char *p = settings;
|
||||
while (p && *p && n < 64)
|
||||
{
|
||||
const char *end = strchr (p, ',');
|
||||
int len = end ? (int) (end - p) : (int) strlen (p);
|
||||
if (hb_feature_from_string (p, len, &feats[n]))
|
||||
n++;
|
||||
p = end ? end + 1 : nullptr;
|
||||
}
|
||||
demo_buffer_set_features (feats, n);
|
||||
rebuild_buffer (custom_text ? current_text : default_text_en);
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void
|
||||
web_set_palette (unsigned palette_index)
|
||||
{
|
||||
|
||||
@@ -700,6 +700,15 @@ tap: animate · dbl-tap+drag: zoom · long-press: reset</span>
|
||||
requestRedraw();
|
||||
}
|
||||
|
||||
function applyFeatures(settings) {
|
||||
var len = lengthBytesUTF8(settings) + 1;
|
||||
var buf = _malloc(len);
|
||||
stringToUTF8(settings, buf, len);
|
||||
_web_set_features(buf);
|
||||
_free(buf);
|
||||
requestRedraw();
|
||||
}
|
||||
|
||||
function applyPalette(idx) {
|
||||
_web_set_palette(idx >>> 0);
|
||||
requestRedraw();
|
||||
@@ -720,6 +729,8 @@ tap: animate · dbl-tap+drag: zoom · long-press: reset</span>
|
||||
applyVariations(d.value);
|
||||
else if (d.kind === 'palette' && typeof d.value === 'number')
|
||||
applyPalette(d.value);
|
||||
else if (d.kind === 'features' && typeof d.value === 'string')
|
||||
applyFeatures(d.value);
|
||||
else if (d.kind === 'dark' && typeof d.value === 'boolean')
|
||||
_web_set_dark(d.value ? 1 : 0);
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user