29#include <proto/bullet.h>
31#include <proto/diskfont.h>
32#include <proto/exec.h>
33#include <proto/graphics.h>
34#include <proto/utility.h>
36#include <diskfont/diskfonttag.h>
37#include <diskfont/oterrors.h>
52#define NSA_UNICODE_FONT PLOT_FONT_FAMILY_COUNT
57#define NSA_BOLDITALIC 3
59#define NSA_BOLDOBLIQUE 6
61#define NSA_VALUE_BOLDX (1 << 12)
62#define NSA_VALUE_BOLDY 0
63#define NSA_VALUE_SHEARSIN (1 << 14)
64#define NSA_VALUE_SHEARCOS (1 << 16)
66#define NSA_FONT_EMWIDTH(s) (s / PLOT_STYLE_SCALE) * (ami_font_dpi_get_xdpi() / 72.0)
150 if (__builtin_expect(((*char1 < 0xD800) || (0xDBFF < *char1)), 1)) {
160 return ((
uint32)char1[0] << 10) + char1[1] - 0x35FDC00;
167 const char *
string,
size_t length,
192 const char *
string,
size_t length,
193 int x,
size_t *char_offset,
int *actual_x)
195 uint16 *utf16 = NULL, *outf16 = NULL;
211 while (utf8_pos < length) {
213 utf16next = &utf16[utf16charlen];
228 utf8_pos =
utf8_next(
string, length, utf8_pos);
232 *char_offset = utf8_pos;
234 if((x - *actual_x) > (tx - x)) {
236 *char_offset = utf8_pos;
244 *char_offset = length;
275 const char *
string,
size_t length,
276 int x,
size_t *char_offset,
int *actual_x)
279 const uint16 *utf16 = NULL;
280 const uint16 *utf16next = NULL;
288 if (
utf8_to_enc(
string,
"UTF-16", length, (
char **)&utf16_str) !=
299 if (*utf16 == 0xFEFF) utf16++;
301 while (utf8_pos < length) {
302 if ((*utf16 < 0xD800) || (0xDBFF < *utf16))
303 utf16next = utf16 + 1;
305 utf16next = utf16 + 2;
319 if (*(
string + utf8_pos) ==
' ') {
322 *char_offset = utf8_pos;
326 if ((x < tx) && (*char_offset != 0)) {
334 utf8_pos =
utf8_next(
string, length, utf8_pos);
340 assert(*char_offset == 0 || x >= tx);
342 *char_offset = length;
353 NSLOG(netsurf, INFO,
"Requested NULL font");
358 if(nodedata)
return nodedata;
362 if(nodedata == NULL) {
371 NSLOG(netsurf, INFO,
"Requested font not found: %s",
font);
379 NSLOG(netsurf, INFO,
"Bold font defined for %s is %s",
font,
383 "Warning: No designed bold font defined for %s",
font);
387 NSLOG(netsurf, INFO,
"Italic font defined for %s is %s",
391 "Warning: No designed italic font defined for %s",
font);
395 NSLOG(netsurf, INFO,
"Bold-italic font defined for %s is %s",
399 "Warning: No designed bold-italic font defined for %s",
426 ULONG shearcos = (1 << 16);
429 else fontfamily = fstyle->
family;
456 if(fontname == NULL)
return NULL;
461 if(!node)
return NULL;
469 if (fstyle->
weight >= 700)
477 if(designed_node == NULL) {
491 if(designed_node == NULL) {
503 if(designed_node == NULL) {
512 if(designed_node == NULL) {
524 if(designed_node == NULL) {
527 ofont = designed_node->
font;
531 struct BulletBase *BulletBase = ofont->
BulletBase;
536 OT_PointHeight, ysize,
537 OT_EmboldenX, emboldenx,
538 OT_EmboldenY, emboldeny,
539 OT_ShearSin, shearsin,
540 OT_ShearCos, shearcos,
541 TAG_END) == OTERR_Success)
551 struct GlyphMap *glyph;
553 int32 char_advance = 0;
557 bool skip_c2 =
false;
558 uint32 long_char_1 = 0, long_char_2 = 0;
560 struct BulletBase *BulletBase = ofont->
BulletBase;
564 if (__builtin_expect(((*char1 >= 0xD800) && (*char1 <= 0xDBFF)), 0)) {
569 if (__builtin_expect(((*char2 >= 0xD800) && (*char2 <= 0xDBFF)), 0)) {
575 if (*char2 < 0x0020) skip_c2 =
true;
578 if(__builtin_expect(aa ==
true, 1)) {
579 glyphmaptag = OT_GlyphMap8Bit;
580 template_type = BLITT_ALPHATEMPLATE;
583 glyphmaptag = OT_GlyphMap;
585 template_type = BLITT_TEMPLATE;
594 OT_GlyphCode, long_char_1,
595 OT_GlyphCode2, long_char_2,
596 TAG_END) == OTERR_Success)
602 glyphbm = glyph->glm_BitMap;
603 if(!glyphbm)
return 0;
607 BltBitMapTags(BLITA_SrcX, glyph->glm_BlackLeft,
608 BLITA_SrcY, glyph->glm_BlackTop,
609 BLITA_DestX, x - glyph->glm_X0 + glyph->glm_BlackLeft,
610 BLITA_DestY, y - glyph->glm_Y0 + glyph->glm_BlackTop,
611 BLITA_Width, glyph->glm_BlackWidth,
612 BLITA_Height, glyph->glm_BlackHeight,
613 BLITA_Source, glyphbm,
614 BLITA_SrcType, template_type,
616 BLITA_DestType, BLITT_RASTPORT,
617 BLITA_SrcBytesPerRow, glyph->glm_BMModulo,
622 if(chip_glyph != NULL) {
623 CopyMem(glyphbm, chip_glyph, glyph->glm_BMModulo * glyph->glm_BMRows);
625 BltTemplate(chip_glyph + (glyph->glm_BMModulo * glyph->glm_BlackTop) +
626 ((glyph->glm_BlackLeft >> 4) << 1),
627 glyph->glm_BlackLeft & 0xF, glyph->glm_BMModulo, rp,
628 x - glyph->glm_X0 + glyph->glm_BlackLeft,
629 y - glyph->glm_Y0 + glyph->glm_BlackTop,
630 glyph->glm_BlackWidth, glyph->glm_BlackHeight);
640 OT_TextKernPair, &kern,
643 char_advance = (ULONG)(((glyph->glm_Width - kern) * emwidth) / 65536);
650 OT_TextKernPair, kern,
661 int32 char_advance = 0;
663 struct MinList *gwlist = NULL;
664 struct GlyphWidthEntry *gwnode;
665 bool skip_c2 =
false;
669 struct BulletBase *BulletBase = ofont->
BulletBase;
673 if (__builtin_expect(((*char1 >= 0xD800) && (*char1 <= 0xDBFF)), 0)) {
678 if (__builtin_expect(((*char2 >= 0xD800) && (*char2 <= 0xDBFF)), 0)) {
684 if (*char2 < 0x0020) skip_c2 =
true;
690 OT_GlyphCode, long_char_1,
691 OT_GlyphCode2, long_char_1,
692 TAG_END) == OTERR_Success)
695 OT_WidthList, &gwlist,
699 gwnode = (
struct GlyphWidthEntry *)
GetHead((
struct List *)gwlist);
700 if(gwnode) char1w = gwnode->gwe_Width;
707 OT_GlyphCode, long_char_1,
708 OT_GlyphCode2, long_char_2,
709 TAG_END) == OTERR_Success)
712 OT_TextKernPair, &kern,
716 char_advance = (ULONG)(((char1w - kern) * emwidth) / 65536);
719 OT_TextKernPair, kern,
723 OT_WidthList, gwlist,
738 if(*p == *utf16char)
return &p[1];
748 uint16 *restrict utf16 = NULL, *restrict outf16 = NULL;
749 uint16 *restrict utf16charsc = 0, *restrict utf16nextsc = 0;
750 uint16 *restrict utf16next = 0;
752 struct OutlineFont *restrict ofont, *restrict ufont = NULL;
758 if(!
string ||
string[0]==
'\0')
return 0;
759 if(!length)
return 0;
760 if(rp == NULL)
return 0;
771 utf16next = &utf16[utf16charlen];
779 dx + x, dy, emwidth, aa);
785 dx + x, dy, emwidth, aa);
797 dx + x, dy, emwidth, aa);
803 utf16 += utf16charlen;
813 uint16 *restrict utf16 = NULL, *restrict outf16 = NULL;
814 uint16 *restrict utf16charsc = 0, *restrict utf16nextsc = 0;
815 uint16 *restrict utf16next = 0;
817 struct OutlineFont *restrict ofont, *restrict ufont = NULL;
823 if(!
string ||
string[0]==
'\0')
return 0;
824 if(!length)
return 0;
835 utf16next = &utf16[utf16charlen];
865 utf16 += utf16charlen;
nserror amiga_warn_user(const char *warning, const char *detail)
Warn the user of an event.
nserror
Enumeration of error codes.
@ NSERROR_INVALID
Invalid data.
static ULONG amiga_nsfont_text(struct RastPort *rp, const char *string, ULONG length, const plot_font_style_t *fstyle, ULONG dx, ULONG dy, bool aa)
static struct ami_font_cache_node * ami_font_open(const char *font, bool critical)
Search for a font in the list and load from disk if not present.
static uint32 amiga_nsfont_decode_surrogate(const uint16 *char1)
void ami_font_finiscanner(void)
const struct ami_font_functions ami_font_bullet_table
#define NSA_VALUE_SHEARSIN
static int amiga_nsfont_utf16_char_length(const uint16 *char1)
#define NSA_FONT_EMWIDTH(s)
static lwc_string * glypharray[0xffff+1]
#define NSA_VALUE_SHEARCOS
static int32 ami_font_plot_glyph(struct OutlineFont *ofont, struct RastPort *rp, uint16 *restrict char1, uint16 *restrict char2, uint32 x, uint32 y, uint32 emwidth, bool aa)
static nserror amiga_nsfont_width(const plot_font_style_t *fstyle, const char *string, size_t length, int *width)
static const uint16 * ami_font_translate_smallcaps(uint16 *utf16char)
static ULONG ami_font_unicode_width(const char *string, ULONG length, const plot_font_style_t *fstyle, ULONG x, ULONG y, bool aa)
static struct List ami_diskfontlib_list
static int32 ami_font_width_glyph(struct OutlineFont *ofont, const uint16 *restrict char1, const uint16 *restrict char2, uint32 emwidth)
void ami_font_initscanner(bool force, bool save)
static nserror amiga_nsfont_split(const plot_font_style_t *fstyle, const char *string, size_t length, int x, size_t *char_offset, int *actual_x)
Find where to split a string to make it fit a width.
void ami_font_bullet_fini(void)
void ami_font_bullet_close(void *nso)
void ami_font_bullet_init(void)
static nserror 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)
Find the position in a string where an x coordinate falls.
void ami_font_savescanner(void)
static struct OutlineFont * ami_open_outline_font(const plot_font_style_t *fstyle, const uint16 *codepoint)
Open an outline font in the specified size and style.
void ami_font_cache_fini(void)
struct ami_font_cache_node * ami_font_cache_alloc_entry(const char *font)
void ami_font_cache_insert(struct ami_font_cache_node *nodedata, const char *font)
void ami_font_cache_init(void)
struct ami_font_cache_node * ami_font_cache_locate(const char *font)
const char * ami_font_scan_lookup(const uint16 *code, lwc_string **glypharray)
Lookup a font that contains a UTF-16 codepoint.
void ami_font_scan_init(const char *filename, bool force_scan, bool save, lwc_string **glypharray)
Initialise the font glyph cache.
void ami_font_scan_save(const char *filename, lwc_string **glypharray)
Save a font glyph cache.
void ami_font_scan_fini(lwc_string **glypharray)
Finalise the font glyph cache.
ULONG ami_font_dpi_get_devicedpi(void)
const struct ami_font_functions * ami_nsfont
#define NSLOG(catname, level, logmsg, args...)
#define ami_memory_chip_free(p)
#define ami_memory_chip_alloc(s)
void CloseOutlineFont(struct OutlineFont *of, struct List *list)
struct OutlineFont * OpenOutlineFont(STRPTR fileName, struct List *list, ULONG flags)
struct Node * GetHead(struct List *list)
Minimal compatibility header for AmigaOS 3.
plot_font_generic_family_t
Generic font family type.
@ PLOT_FONT_FAMILY_CURSIVE
@ PLOT_FONT_FAMILY_SANS_SERIF
@ PLOT_FONT_FAMILY_FANTASY
@ PLOT_FONT_FAMILY_MONOSPACE
#define PLOT_STYLE_SCALE
Scaling factor for plot styles.
struct TagItem * olf_OTagList
struct BulletBase * BulletBase
struct OutlineFont * font
char *restrict bolditalic
plot_font_generic_family_t family
Generic family to plot with.
plot_font_flags_t flags
Font flags.
plot_style_fixed size
Font size, in pt.
int weight
Font weight: value in range [100,900] as per CSS.
Option reading and saving interface.
#define nsoption_charp(OPTION)
Get the value of a string option.
size_t utf8_next(const char *s, size_t l, size_t o)
Find next legal UTF-8 char in string.
nserror utf8_to_enc(const char *string, const char *encname, size_t len, char **result)
Convert a UTF8 string into the named encoding.
UTF-8 manipulation functions (interface).
Interface to a number of general purpose functionality.