136 lines
4.4 KiB
Diff
136 lines
4.4 KiB
Diff
diff --git a/frontends/monkey/plot.c b/frontends/monkey/plot.c
|
|
--- a/frontends/monkey/plot.c
|
|
+++ b/frontends/monkey/plot.c
|
|
@@ -27,7 +27,7 @@
|
|
#include "monkey/browser.h"
|
|
|
|
#if defined(__montauk__)
|
|
-extern const unsigned char mtk_font_data[] __asm__("_ZN3gui9font_dataE");
|
|
+#include "content/fetchers/montauk_bridge.h"
|
|
|
|
struct bitmap {
|
|
void *ptr;
|
|
@@ -69,20 +69,10 @@ static void native_text(struct gui_window *gw, int x, int baseline,
|
|
const char *text, size_t length, const struct plot_font_style *style)
|
|
{
|
|
int px = plot_style_fixed_to_int(style->size);
|
|
- int sx = px > 8 ? px / 8 : 1;
|
|
- int sy = px > 16 ? px / 16 : 1;
|
|
- int top = baseline - 13 * sy;
|
|
- uint32_t colour = native_colour(style->foreground);
|
|
- for (size_t i = 0; i < length; i++) {
|
|
- unsigned char ch = (unsigned char)text[i];
|
|
- if (ch >= 128) continue;
|
|
- const unsigned char *glyph = mtk_font_data + ch * 16;
|
|
- for (int row = 0; row < 16; row++)
|
|
- for (int col = 0; col < 8; col++)
|
|
- if (glyph[row] & (0x80u >> col))
|
|
- native_fill(gw, x + col * sx, top + row * sy,
|
|
- x + (col + 1) * sx, top + (row + 1) * sy, colour);
|
|
- x += px > 0 ? px : 8;
|
|
- }
|
|
+ if (gw == NULL || gw->pixels == NULL) return;
|
|
+ mtk_netsurf_font_draw(gw->pixels, gw->width, gw->height,
|
|
+ gw->clip_x0, gw->clip_y0, gw->clip_x1, gw->clip_y1,
|
|
+ x, baseline, text, length, native_colour(style->foreground),
|
|
+ style->family, style->weight, style->flags, px);
|
|
}
|
|
#endif
|
|
diff --git a/frontends/monkey/layout.c b/frontends/monkey/layout.c
|
|
--- a/frontends/monkey/layout.c
|
|
+++ b/frontends/monkey/layout.c
|
|
@@ -30,10 +30,25 @@
|
|
|
|
#include "monkey/layout.h"
|
|
|
|
+#if defined(__montauk__)
|
|
+#include "content/fetchers/montauk_bridge.h"
|
|
+#endif
|
|
+
|
|
+static int font_width(const plot_font_style_t *fstyle,
|
|
+ const char *string, size_t length)
|
|
+{
|
|
+#if defined(__montauk__)
|
|
+ return mtk_netsurf_font_width(fstyle->family, fstyle->weight,
|
|
+ fstyle->flags, plot_style_fixed_to_int(fstyle->size), string, length);
|
|
+#else
|
|
+ return (fstyle->size * utf8_bounded_length(string, length)) / PLOT_STYLE_SCALE;
|
|
+#endif
|
|
+}
|
|
+
|
|
static nserror nsfont_width(const plot_font_style_t *fstyle,
|
|
const char *string, size_t length,
|
|
int *width)
|
|
{
|
|
- *width = (fstyle->size * utf8_bounded_length(string, length)) / PLOT_STYLE_SCALE;
|
|
+ *width = font_width(fstyle, string, length);
|
|
return NSERROR_OK;
|
|
}
|
|
@@ -55,8 +70,22 @@ static nserror nsfont_position_in_string(const plot_font_style_t *fstyle,
|
|
int x, size_t *char_offset, int *actual_x)
|
|
{
|
|
- *char_offset = x / (fstyle->size / PLOT_STYLE_SCALE);
|
|
- if (*char_offset > length)
|
|
- *char_offset = length;
|
|
- *actual_x = *char_offset * (fstyle->size / PLOT_STYLE_SCALE);
|
|
+ size_t offset = 0, previous = 0;
|
|
+ int previous_width = 0;
|
|
+ while (offset < length) {
|
|
+ previous = offset;
|
|
+ offset = utf8_next(string, length, offset);
|
|
+ int next_width = font_width(fstyle, string, offset);
|
|
+ if (next_width > x) {
|
|
+ if (x - previous_width > next_width - x) {
|
|
+ *char_offset = offset; *actual_x = next_width;
|
|
+ } else {
|
|
+ *char_offset = previous; *actual_x = previous_width;
|
|
+ }
|
|
+ return NSERROR_OK;
|
|
+ }
|
|
+ previous_width = next_width;
|
|
+ }
|
|
+ *char_offset = length;
|
|
+ *actual_x = previous_width;
|
|
return NSERROR_OK;
|
|
}
|
|
@@ -90,21 +119,25 @@ static nserror nsfont_split(const plot_font_style_t *fstyle,
|
|
int x, size_t *char_offset, int *actual_x)
|
|
{
|
|
- int c_off = *char_offset = x / (fstyle->size / PLOT_STYLE_SCALE);
|
|
- if (*char_offset > length) {
|
|
+ size_t offset = 0, last_space = 0, first_over = length;
|
|
+ while (offset < length) {
|
|
+ size_t next = utf8_next(string, length, offset);
|
|
+ if (string[offset] == ' ') last_space = offset;
|
|
+ if (font_width(fstyle, string, next) > x) {
|
|
+ first_over = next;
|
|
+ break;
|
|
+ }
|
|
+ offset = next;
|
|
+ }
|
|
+ if (first_over == length && font_width(fstyle, string, length) <= x) {
|
|
*char_offset = length;
|
|
+ } else if (last_space != 0) {
|
|
+ *char_offset = last_space;
|
|
} else {
|
|
- while (*char_offset > 0) {
|
|
- if (string[*char_offset] == ' ')
|
|
- break;
|
|
- (*char_offset)--;
|
|
- }
|
|
- if (*char_offset == 0) {
|
|
- *char_offset = c_off;
|
|
- while (*char_offset < length && string[*char_offset] != ' ') {
|
|
- (*char_offset)++;
|
|
- }
|
|
- }
|
|
+ *char_offset = first_over;
|
|
+ while (*char_offset < length && string[*char_offset] != ' ')
|
|
+ (*char_offset)++;
|
|
}
|
|
- *actual_x = *char_offset * (fstyle->size / PLOT_STYLE_SCALE);
|
|
+ if (*char_offset == 0) *char_offset = first_over != 0 ? first_over : length;
|
|
+ *actual_x = font_width(fstyle, string, *char_offset);
|
|
return NSERROR_OK;
|
|
}
|