summaryrefslogtreecommitdiff
path: root/riscos/font.c
diff options
context:
space:
mode:
authorPhil Mellor <phil@monkeyson.info>2002-09-11 14:24:02 +0000
committerPhil Mellor <phil@monkeyson.info>2002-09-11 14:24:02 +0000
commit811106028fd050cdee11fbc8732ba39f2de5e12a (patch)
tree0194609193dc142881958ff81bef57f07da71b54 /riscos/font.c
parenta46eef0002d061c3363756182a592be7646ae79b (diff)
downloadnetsurf-811106028fd050cdee11fbc8732ba39f2de5e12a.tar.gz
netsurf-811106028fd050cdee11fbc8732ba39f2de5e12a.tar.bz2
[project @ 2002-09-11 14:24:02 by monkeyson]
RISC OS Wimp GUI. svn path=/import/netsurf/; revision=33
Diffstat (limited to 'riscos/font.c')
-rw-r--r--riscos/font.c86
1 files changed, 82 insertions, 4 deletions
diff --git a/riscos/font.c b/riscos/font.c
index a12ff2241..05faf50cf 100644
--- a/riscos/font.c
+++ b/riscos/font.c
@@ -1,31 +1,56 @@
/**
- * $Id: font.c,v 1.1 2002/07/27 21:10:45 bursa Exp $
+ * $Id: font.c,v 1.2 2002/09/11 14:24:02 monkeyson Exp $
*/
#include <stdio.h>
#include "netsurf/render/css.h"
#include "netsurf/render/font.h"
#include "netsurf/render/utils.h"
+#include "netsurf/desktop/gui.h"
#include "oslib/font.h"
/**
* functions
*/
-extern font_f font;
+/** it is rather inefficient calling this all the time **/
+font_f riscos_font_css_to_handle(struct css_style* style)
+{
+ int width = 12 * 16;
+ int height = 12 * 16;
+ char font_name[255];
+
+ if (style->font_size.size == CSS_FONT_SIZE_LENGTH)
+ width = height = style->font_size.value.length.value * 16;
+
+ strcpy(font_name, "Homerton.");
+ if (style->font_weight == CSS_FONT_WEIGHT_BOLD)
+ strcat(font_name, "Bold");
+ else
+ strcat(font_name, "Medium");
+
+ if (style->font_style == CSS_FONT_STYLE_ITALIC || style->font_style == CSS_FONT_STYLE_OBLIQUE)
+ strcat(font_name, ".Oblique");
+
+ return font_find_font(font_name, width, height, 0, 0, 0, 0);
+}
unsigned long font_width(struct css_style * style, const char * text, unsigned int length)
{
font_scan_block block;
os_error * error;
+ font_f font;
- if (length == 0) return 0;
+ if (length == 0)
+ return 0;
block.space.x = block.space.y = 0;
block.letter.x = block.letter.y = 0;
block.split_char = -1;
- error = xfont_scan_string(font, text,
+ font = riscos_font_css_to_handle(style);
+
+ error = xfont_scan_string(font, (char*) text,
font_GIVEN_BLOCK | font_GIVEN_LENGTH | font_GIVEN_FONT | font_KERN | font_RETURN_BBOX,
0x7fffffff, 0x7fffffff,
&block,
@@ -35,6 +60,59 @@ unsigned long font_width(struct css_style * style, const char * text, unsigned i
fprintf(stderr, "%s\n", error->errmess);
die("font_scan_string failed");
}
+
+// fprintf(stderr, "Stated length %d, strlen %d\n", (int)length, strlen(text));
+
+ if (length < 0x7fffffff)
+ {
+ if (text[length - 1] == ' ')
+// {
+ block.bbox.x1 += 4*800;
+/* int minx,miny,maxx,maxy;
+ char space = ' ';
+// fprintf(stderr, "Space at the end!\n");
+ error = xfont_char_bbox(font, space, 0, &minx, &miny, &maxx, &maxy);
+ if (error != 0) {
+ fprintf(stderr, "%s\n", error->errmess);
+ die("font_char_bbox failed");
+ }
+ block.bbox.x1 += maxx;
+ }
+// else
+// fprintf(stderr, "No space\n");*/
+ }
+
+ font_lose_font(font);
+
return block.bbox.x1 / 800;
}
+void font_position_in_string(const char* text, struct css_style* style, int length, int x, int* char_offset, int* pixel_offset)
+{
+ font_f font;
+ font_scan_block block;
+ char* split_point;
+ int x_out, y_out, length_out;
+
+ block.space.x = block.space.y = 0;
+ block.letter.x = block.letter.y = 0;
+ block.split_char = -1;
+
+ font = riscos_font_css_to_handle(style);
+
+ xfont_scan_string(font, (char*) text,
+ font_GIVEN_BLOCK | font_GIVEN_LENGTH |
+ font_GIVEN_FONT | font_KERN | font_RETURN_CARET_POS,
+ ro_x_units(x) * 400,
+ 0x7fffffff,
+ &block, 0, length,
+ &split_point, &x_out, &y_out, &length_out);
+
+ font_lose_font(font);
+
+ *char_offset = (int)(split_point - text);
+ *pixel_offset = browser_x_units(x_out / 400);
+
+ return;
+}
+