summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--amiga/Makefile.target3
-rw-r--r--amiga/font.c72
-rwxr-xr-xamiga/font.h14
-rw-r--r--amiga/font_bitmap.c215
-rw-r--r--amiga/options.h1
5 files changed, 283 insertions, 22 deletions
diff --git a/amiga/Makefile.target b/amiga/Makefile.target
index 7d858ef8a..902770722 100644
--- a/amiga/Makefile.target
+++ b/amiga/Makefile.target
@@ -74,7 +74,8 @@ S_AMIGA := gui.c tree.c history.c hotlist.c schedule.c file.c \
sslcert.c gui_options.c print.c theme.c drag.c icon.c libs.c \
datatypes.c dt_picture.c dt_anim.c dt_sound.c plugin_hack.c \
stringview/stringview.c stringview/urlhistory.c rtg.c \
- agclass/amigaguide_class.c fs_backing_store.c os3support.c
+ agclass/amigaguide_class.c fs_backing_store.c os3support.c \
+ font_bitmap.c
S_AMIGA := $(addprefix amiga/,$(S_AMIGA))
# This is the final source build list
diff --git a/amiga/font.c b/amiga/font.c
index 435e75992..80e34bd10 100644
--- a/amiga/font.c
+++ b/amiga/font.c
@@ -160,26 +160,8 @@ struct OutlineFont *ami_open_outline_font(const plot_font_style_t *fstyle,
const uint16 *codepoint);
static void ami_font_cleanup(struct MinList *ami_font_list);
-static bool nsfont_width(const plot_font_style_t *fstyle,
- const char *string, size_t length,
- int *width);
-
-static bool nsfont_position_in_string(const plot_font_style_t *fstyle,
- const char *string, size_t length,
- int x, size_t *char_offset, int *actual_x);
-
-static bool nsfont_split(const plot_font_style_t *fstyle,
- const char *string, size_t length,
- int x, size_t *char_offset, int *actual_x);
-const struct font_functions nsfont = {
- nsfont_width,
- nsfont_position_in_string,
- nsfont_split
-};
-
-
-bool nsfont_width(const plot_font_style_t *fstyle,
+static bool amiga_nsfont_width(const plot_font_style_t *fstyle,
const char *string, size_t length,
int *width)
{
@@ -202,7 +184,7 @@ bool nsfont_width(const plot_font_style_t *fstyle,
* \return true on success, false on error and error reported
*/
-bool nsfont_position_in_string(const plot_font_style_t *fstyle,
+static bool amiga_nsfont_position_in_string(const plot_font_style_t *fstyle,
const char *string, size_t length,
int x, size_t *char_offset, int *actual_x)
{
@@ -289,7 +271,7 @@ bool nsfont_position_in_string(const plot_font_style_t *fstyle,
* Returning char_offset == length means no split possible
*/
-bool nsfont_split(const plot_font_style_t *fstyle,
+static bool amiga_nsfont_split(const plot_font_style_t *fstyle,
const char *string, size_t length,
int x, size_t *char_offset, int *actual_x)
{
@@ -752,6 +734,10 @@ ULONG ami_unicode_text(struct RastPort *rp, const char *string, ULONG length,
if(!string || string[0]=='\0') return 0;
if(!length) return 0;
+ if(nsoption_bool(use_diskfont) == true) {
+ return ami_font_bm_text(rp, string, length, fstyle, dx, dy);
+ }
+
if(utf8_to_enc(string,"UTF-16",length,(char **)&utf16) != NSERROR_OK) return 0;
outf16 = utf16;
if(!(ofont = ami_open_outline_font(fstyle, 0))) return 0;
@@ -949,3 +935,47 @@ void ami_font_close_disk_font(struct TextFont *tfont)
{
CloseFont(tfont);
}
+
+
+/* Stub entry points */
+static bool nsfont_width(const plot_font_style_t *fstyle,
+ const char *string, size_t length,
+ int *width)
+{
+ if(nsoption_bool(use_diskfont) == false) {
+ return amiga_nsfont_width(fstyle, string, length, width);
+ } else {
+ return amiga_bm_nsfont_width(fstyle, string, length, width);
+ }
+}
+
+static bool nsfont_position_in_string(const plot_font_style_t *fstyle,
+ const char *string, size_t length,
+ int x, size_t *char_offset, int *actual_x)
+{
+ if(nsoption_bool(use_diskfont) == false) {
+ return amiga_nsfont_position_in_string(fstyle, string, length, x,
+ char_offset, actual_x);
+ } else {
+ return amiga_bm_nsfont_position_in_string(fstyle, string, length, x,
+ char_offset, actual_x);
+ }
+}
+
+static bool nsfont_split(const plot_font_style_t *fstyle,
+ const char *string, size_t length,
+ int x, size_t *char_offset, int *actual_x)
+{
+ if(nsoption_bool(use_diskfont) == false) {
+ return amiga_nsfont_split(fstyle, string, length, x, char_offset, actual_x);
+ } else {
+ return amiga_bm_nsfont_split(fstyle, string, length, x, char_offset, actual_x);
+ }
+}
+
+const struct font_functions nsfont = {
+ nsfont_width,
+ nsfont_position_in_string,
+ nsfont_split
+};
+
diff --git a/amiga/font.h b/amiga/font.h
index 10137f777..6c600abe4 100755
--- a/amiga/font.h
+++ b/amiga/font.h
@@ -40,4 +40,18 @@ void ami_font_savescanner(void);
/* Simple diskfont functions for graphics.library use (not page rendering) */
struct TextFont *ami_font_open_disk_font(struct TextAttr *tattr);
void ami_font_close_disk_font(struct TextFont *tfont);
+
+/* In font_bitmap.c */
+bool amiga_bm_nsfont_width(const plot_font_style_t *fstyle,
+ const char *string, size_t length, int *width);
+bool amiga_bm_nsfont_position_in_string(const plot_font_style_t *fstyle,
+ const char *string, size_t length,
+ int x, size_t *char_offset, int *actual_x);
+bool amiga_bm_nsfont_split(const plot_font_style_t *fstyle,
+ const char *string, size_t length,
+ int x, size_t *char_offset, int *actual_x);
+ULONG ami_font_bm_text(struct RastPort *rp, const char *string, ULONG length,
+ const plot_font_style_t *fstyle, ULONG dx, ULONG dy);
+
#endif
+
diff --git a/amiga/font_bitmap.c b/amiga/font_bitmap.c
new file mode 100644
index 000000000..d620ea90c
--- /dev/null
+++ b/amiga/font_bitmap.c
@@ -0,0 +1,215 @@
+/*
+ * Copyright 2008 - 2015 Chris Young <chris@unsatisfactorysoftware.co.uk>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "amiga/os3support.h"
+
+#include <assert.h>
+
+#include <proto/diskfont.h>
+#include <proto/exec.h>
+#include <proto/graphics.h>
+#include <proto/timer.h>
+#include <proto/utility.h>
+
+#include <graphics/rpattr.h>
+
+#include "utils/log.h"
+#include "utils/utf8.h"
+#include "utils/utils.h"
+#include "utils/nsoption.h"
+#include "desktop/browser.h"
+#include "desktop/font.h"
+#include "desktop/gui_window.h"
+
+#include "amiga/font.h"
+#include "amiga/gui.h"
+#include "amiga/utf8.h"
+
+static struct TextFont *ami_font_bm_open(struct RastPort *rp, const plot_font_style_t *fstyle)
+{
+ struct TextFont *bmfont = NULL;
+ struct TextAttr tattr;
+ char *fontname, font;
+
+ if(rp == NULL) return NULL;
+
+ switch(fstyle->family)
+ {
+ case PLOT_FONT_FAMILY_SANS_SERIF:
+ fontname = nsoption_charp(font_sans);
+ break;
+ case PLOT_FONT_FAMILY_SERIF:
+ fontname = nsoption_charp(font_serif);
+ break;
+ case PLOT_FONT_FAMILY_MONOSPACE:
+ fontname = nsoption_charp(font_mono);
+ break;
+ case PLOT_FONT_FAMILY_CURSIVE:
+ fontname = nsoption_charp(font_cursive);
+ break;
+ case PLOT_FONT_FAMILY_FANTASY:
+ fontname = nsoption_charp(font_fantasy);
+ break;
+ default:
+ return NULL;
+ break;
+ }
+
+ tattr.ta_Style = FS_NORMAL;
+
+ if (fstyle->flags & FONTF_OBLIQUE)
+ tattr.ta_Style = FSF_ITALIC;
+
+ if (fstyle->flags & FONTF_ITALIC)
+ tattr.ta_Style = FSF_ITALIC;
+
+ if (fstyle->weight >= 700)
+ tattr.ta_Style |= FSF_BOLD;
+
+ if(font = ASPrintf("%s.font", fontname)) {
+ tattr.ta_Name = font;
+ tattr.ta_YSize = fstyle->size / FONT_SIZE_SCALE;
+
+ if(bmfont = OpenDiskFont(&tattr)) {
+ SetRPAttrs(rp, RPTAG_Font, bmfont, TAG_DONE);
+ }
+ FreeVec(font);
+ }
+
+ return bmfont;
+}
+
+static void ami_font_bm_close(struct TextFont *bmfont)
+{
+ CloseFont(bmfont);
+}
+
+bool amiga_bm_nsfont_width(const plot_font_style_t *fstyle,
+ const char *string, size_t length,
+ int *width)
+{
+ struct TextFont *bmfont = ami_font_bm_open(glob->rp, fstyle);
+// convert to local charset
+ *width = TextLength(glob->rp, string, length);
+ ami_font_bm_close(bmfont);
+
+ return true;
+}
+
+/**
+ * Find the position in a string where an x coordinate falls.
+ *
+ * \param fstyle style for this text
+ * \param string UTF-8 string to measure
+ * \param length length of string
+ * \param x x coordinate to search for
+ * \param char_offset updated to offset in string of actual_x, [0..length]
+ * \param actual_x updated to x coordinate of character closest to x
+ * \return true on success, false on error and error reported
+ */
+
+bool amiga_bm_nsfont_position_in_string(const plot_font_style_t *fstyle,
+ const char *string, size_t length,
+ int x, size_t *char_offset, int *actual_x)
+{
+ struct TextExtent extent;
+ struct TextFont *bmfont;
+
+ bmfont = ami_font_bm_open(glob->rp, fstyle);
+
+ // convert to local charset
+ *char_offset = TextFit(glob->rp, string, length,
+ &extent, NULL, 1, x, 32767);
+
+ *actual_x = extent.te_Extent.MaxX;
+
+ ami_font_bm_close(bmfont);
+
+ return true;
+}
+
+
+/**
+ * Find where to split a string to make it fit a width.
+ *
+ * \param fstyle style for this text
+ * \param string UTF-8 string to measure
+ * \param length length of string
+ * \param x width available
+ * \param char_offset updated to offset in string of actual_x, [1..length]
+ * \param actual_x updated to x coordinate of character closest to x
+ * \return true on success, false on error and error reported
+ *
+ * On exit, char_offset indicates first character after split point.
+ *
+ * Note: char_offset of 0 should never be returned.
+ *
+ * Returns:
+ * char_offset giving split point closest to x, where actual_x <= x
+ * else
+ * char_offset giving split point closest to x, where actual_x > x
+ *
+ * Returning char_offset == length means no split possible
+ */
+
+bool amiga_bm_nsfont_split(const plot_font_style_t *fstyle,
+ const char *string, size_t length,
+ int x, size_t *char_offset, int *actual_x)
+{
+ struct TextExtent extent;
+ ULONG co;
+ char *charp;
+ struct TextFont *bmfont = ami_font_bm_open(glob->rp, fstyle);
+
+ co = TextFit(glob->rp, string, length,
+ &extent, NULL, 1, x, 32767);
+
+ charp = string + co;
+
+ while(((*charp != ' ')) && (charp > string)) {
+ charp--;
+ co--;
+ }
+
+ *char_offset = co;
+ if(string && co) {
+ *actual_x = TextLength(glob->rp, string, co);
+ } else {
+ *actual_x = 0;
+ }
+
+ ami_font_bm_close(bmfont);
+
+ return true;
+}
+
+ULONG ami_font_bm_text(struct RastPort *rp, const char *string, ULONG length,
+ const plot_font_style_t *fstyle, ULONG dx, ULONG dy)
+{
+ struct TextFont *bmfont = ami_font_bm_open(rp, fstyle);
+ char *localtext = NULL;
+ if(bmfont == NULL) return 0;
+ if(utf8_to_local_encoding(string, length, &localtext) == NSERROR_OK) {
+ Move(rp, dx, dy);
+ Text(rp, localtext, length);
+ free(localtext);
+ }
+
+ return 0;
+}
+
diff --git a/amiga/options.h b/amiga/options.h
index 868e28fdb..b94242085 100644
--- a/amiga/options.h
+++ b/amiga/options.h
@@ -63,6 +63,7 @@ NSOPTION_STRING(font_unicode, NULL)
NSOPTION_STRING(font_unicode_file, NULL)
NSOPTION_BOOL(font_unicode_only, false)
NSOPTION_BOOL(font_antialiasing, true)
+NSOPTION_BOOL(use_diskfont, false)
NSOPTION_BOOL(drag_save_icons, true)
NSOPTION_INTEGER(hotlist_window_xpos, 0)
NSOPTION_INTEGER(hotlist_window_ypos, 0)