NetSurf
Macros | Functions | Variables
font_bullet.c File Reference

Amiga font handling implementation. More...

#include "amiga/os3support.h"
#include <stdlib.h>
#include <proto/bullet.h>
#include <proto/diskfont.h>
#include <proto/exec.h>
#include <proto/graphics.h>
#include <proto/utility.h>
#include <diskfont/diskfonttag.h>
#include <diskfont/oterrors.h>
#include "utils/log.h"
#include "utils/nsoption.h"
#include "utils/utf8.h"
#include "utils/utils.h"
#include "amiga/memory.h"
#include "amiga/misc.h"
#include "amiga/font.h"
#include "amiga/font_bullet.h"
#include "amiga/font_cache.h"
#include "amiga/font_scan.h"
Include dependency graph for font_bullet.c:

Go to the source code of this file.

Macros

#define NSA_UNICODE_FONT   PLOT_FONT_FAMILY_COUNT
 
#define NSA_NORMAL   0
 
#define NSA_ITALIC   1
 
#define NSA_BOLD   2
 
#define NSA_BOLDITALIC   3
 
#define NSA_OBLIQUE   4
 
#define NSA_BOLDOBLIQUE   6
 
#define NSA_VALUE_BOLDX   (1 << 12)
 
#define NSA_VALUE_BOLDY   0
 
#define NSA_VALUE_SHEARSIN   (1 << 14)
 
#define NSA_VALUE_SHEARCOS   (1 << 16)
 
#define NSA_FONT_EMWIDTH(s)   (s / PLOT_STYLE_SCALE) * (ami_font_dpi_get_xdpi() / 72.0)
 

Functions

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 int32 ami_font_width_glyph (struct OutlineFont *ofont, const uint16 *restrict char1, const uint16 *restrict char2, uint32 emwidth)
 
static struct OutlineFontami_open_outline_font (const plot_font_style_t *fstyle, const uint16 *codepoint)
 Open an outline font in the specified size and style. More...
 
static ULONG ami_font_unicode_width (const char *string, ULONG length, const plot_font_style_t *fstyle, ULONG x, ULONG y, bool aa)
 
static int amiga_nsfont_utf16_char_length (const uint16 *char1)
 
static uint32 amiga_nsfont_decode_surrogate (const uint16 *char1)
 
static nserror amiga_nsfont_width (const plot_font_style_t *fstyle, const char *string, size_t length, int *width)
 
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. More...
 
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. More...
 
static struct ami_font_cache_nodeami_font_open (const char *font, bool critical)
 Search for a font in the list and load from disk if not present. More...
 
static const uint16ami_font_translate_smallcaps (uint16 *utf16char)
 
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)
 
void ami_font_bullet_close (void *nso)
 
void ami_font_bullet_init (void)
 
void ami_font_bullet_fini (void)
 
void ami_font_initscanner (bool force, bool save)
 
void ami_font_finiscanner (void)
 
void ami_font_savescanner (void)
 

Variables

const uint16 sc_table []
 
static lwc_string * glypharray [0xffff+1]
 
static struct List ami_diskfontlib_list
 
const struct ami_font_functions ami_font_bullet_table
 

Detailed Description

Amiga font handling implementation.

Definition in file font_bullet.c.

Macro Definition Documentation

◆ NSA_BOLD

#define NSA_BOLD   2

Definition at line 56 of file font_bullet.c.

◆ NSA_BOLDITALIC

#define NSA_BOLDITALIC   3

Definition at line 57 of file font_bullet.c.

◆ NSA_BOLDOBLIQUE

#define NSA_BOLDOBLIQUE   6

Definition at line 59 of file font_bullet.c.

◆ NSA_FONT_EMWIDTH

#define NSA_FONT_EMWIDTH (   s)    (s / PLOT_STYLE_SCALE) * (ami_font_dpi_get_xdpi() / 72.0)

Definition at line 66 of file font_bullet.c.

◆ NSA_ITALIC

#define NSA_ITALIC   1

Definition at line 55 of file font_bullet.c.

◆ NSA_NORMAL

#define NSA_NORMAL   0

Definition at line 54 of file font_bullet.c.

◆ NSA_OBLIQUE

#define NSA_OBLIQUE   4

Definition at line 58 of file font_bullet.c.

◆ NSA_UNICODE_FONT

#define NSA_UNICODE_FONT   PLOT_FONT_FAMILY_COUNT

Definition at line 52 of file font_bullet.c.

◆ NSA_VALUE_BOLDX

#define NSA_VALUE_BOLDX   (1 << 12)

Definition at line 61 of file font_bullet.c.

◆ NSA_VALUE_BOLDY

#define NSA_VALUE_BOLDY   0

Definition at line 62 of file font_bullet.c.

◆ NSA_VALUE_SHEARCOS

#define NSA_VALUE_SHEARCOS   (1 << 16)

Definition at line 64 of file font_bullet.c.

◆ NSA_VALUE_SHEARSIN

#define NSA_VALUE_SHEARSIN   (1 << 14)

Definition at line 63 of file font_bullet.c.

Function Documentation

◆ ami_font_bullet_close()

void ami_font_bullet_close ( void *  nso)

Definition at line 872 of file font_bullet.c.

References ami_diskfontlib_list, CloseOutlineFont(), and ami_font_cache_node::font.

Referenced by ami_font_cache_insert().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ami_font_bullet_fini()

void ami_font_bullet_fini ( void  )

Definition at line 900 of file font_bullet.c.

References ami_font_cache_fini(), and ami_font_finiscanner().

Referenced by ami_font_fini().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ami_font_bullet_init()

void ami_font_bullet_init ( void  )

Definition at line 885 of file font_bullet.c.

References ami_diskfontlib_list, ami_font_bullet_table, ami_font_cache_init(), ami_font_initscanner(), and ami_nsfont.

Referenced by ami_font_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ami_font_finiscanner()

void ami_font_finiscanner ( void  )

Definition at line 912 of file font_bullet.c.

References ami_font_scan_fini(), and glypharray.

Referenced by ami_font_bullet_fini(), and ami_gui_opts_use().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ami_font_initscanner()

void ami_font_initscanner ( bool  force,
bool  save 
)

Definition at line 907 of file font_bullet.c.

References ami_font_scan_init(), glypharray, and nsoption_charp.

Referenced by ami_font_bullet_init(), and ami_gui_opts_use().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ami_font_open()

static struct ami_font_cache_node * ami_font_open ( const char *  font,
bool  critical 
)
static

Search for a font in the list and load from disk if not present.

Definition at line 350 of file font_bullet.c.

References ami_diskfontlib_list, ami_font_cache_alloc_entry(), ami_font_cache_insert(), ami_font_cache_locate(), amiga_warn_user(), ami_font_cache_node::bold, ami_font_cache_node::bolditalic, ami_font_cache_node::font, ami_font_cache_node::italic, NSLOG, OFF_OPEN, OutlineFont::olf_OTagList, and OpenOutlineFont().

Referenced by ami_open_outline_font().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ami_font_plot_glyph()

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 
)
inlinestatic
Todo:
use OT_GlyphCode_32 so we get an error for old font engines

Definition at line 547 of file font_bullet.c.

References ami_memory_chip_alloc, ami_memory_chip_free, AMI_OFONT_ENGINE, amiga_nsfont_decode_surrogate(), OutlineFont::BulletBase, EObtainInfo, EReleaseInfo, and ESetInfo.

Referenced by amiga_nsfont_text().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ami_font_savescanner()

void ami_font_savescanner ( void  )

Definition at line 917 of file font_bullet.c.

References ami_font_scan_save(), glypharray, and nsoption_charp.

Referenced by ami_gui_opts_use().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ami_font_translate_smallcaps()

static const uint16 * ami_font_translate_smallcaps ( uint16 utf16char)
static

Definition at line 731 of file font_bullet.c.

References sc_table.

Referenced by ami_font_unicode_width(), and amiga_nsfont_text().

Here is the caller graph for this function:

◆ ami_font_unicode_width()

static ULONG ami_font_unicode_width ( const char *  string,
ULONG  length,
const plot_font_style_t fstyle,
ULONG  x,
ULONG  y,
bool  aa 
)
inlinestatic

Definition at line 810 of file font_bullet.c.

References ami_font_translate_smallcaps(), ami_font_width_glyph(), ami_open_outline_font(), amiga_nsfont_utf16_char_length(), plot_font_style::flags, FONTF_SMALLCAPS, NSA_FONT_EMWIDTH, NSERROR_OK, plot_font_style::size, and utf8_to_enc().

Referenced by amiga_nsfont_width().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ami_font_width_glyph()

static int32 ami_font_width_glyph ( struct OutlineFont ofont,
const uint16 *restrict  char1,
const uint16 *restrict  char2,
uint32  emwidth 
)
inlinestatic
Todo:
use OT_GlyphCode_32 so we get an error for old font engines

Definition at line 658 of file font_bullet.c.

References AMI_OFONT_ENGINE, amiga_nsfont_decode_surrogate(), OutlineFont::BulletBase, EObtainInfo, EReleaseInfo, ESetInfo, and GetHead().

Referenced by ami_font_unicode_width(), amiga_nsfont_position_in_string(), and amiga_nsfont_split().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ami_open_outline_font()

static struct OutlineFont * ami_open_outline_font ( const plot_font_style_t fstyle,
const uint16 codepoint 
)
static

Open an outline font in the specified size and style.

Parameters
fstylefont style structure
codepointopen a default font instead of the one specified by fstyle
Returns
outline font or NULL on error

Definition at line 413 of file font_bullet.c.

References ami_font_dpi_get_devicedpi(), ami_font_open(), ami_font_scan_lookup(), AMI_OFONT_ENGINE, amiga_nsfont_utf16_char_length(), ami_font_cache_node::bold, ami_font_cache_node::bolditalic, OutlineFont::BulletBase, ESetInfo, plot_font_style::family, plot_font_style::flags, ami_font_cache_node::font, FONTF_ITALIC, FONTF_OBLIQUE, glypharray, ami_font_cache_node::italic, NSA_BOLD, NSA_BOLDITALIC, NSA_BOLDOBLIQUE, NSA_ITALIC, NSA_OBLIQUE, NSA_UNICODE_FONT, NSA_VALUE_BOLDX, NSA_VALUE_BOLDY, NSA_VALUE_SHEARCOS, NSA_VALUE_SHEARSIN, nsoption_charp, PLOT_FONT_FAMILY_CURSIVE, PLOT_FONT_FAMILY_FANTASY, PLOT_FONT_FAMILY_MONOSPACE, PLOT_FONT_FAMILY_SANS_SERIF, PLOT_FONT_FAMILY_SERIF, PLOT_STYLE_SCALE, plot_font_style::size, and plot_font_style::weight.

Referenced by ami_font_unicode_width(), amiga_nsfont_position_in_string(), amiga_nsfont_split(), and amiga_nsfont_text().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ amiga_nsfont_decode_surrogate()

static uint32 amiga_nsfont_decode_surrogate ( const uint16 char1)
inlinestatic

Definition at line 157 of file font_bullet.c.

References amiga_nsfont_utf16_char_length().

Referenced by ami_font_plot_glyph(), and ami_font_width_glyph().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ amiga_nsfont_position_in_string()

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 
)
static

Find the position in a string where an x coordinate falls.

Parameters
fstylestyle for this text
stringUTF-8 string to measure
lengthlength of string
xx coordinate to search for
char_offsetupdated to offset in string of actual_x, [0..length]
actual_xupdated to x coordinate of character closest to x
Returns
true on success, false on error and error reported

Definition at line 191 of file font_bullet.c.

References ami_font_width_glyph(), ami_open_outline_font(), amiga_nsfont_utf16_char_length(), NSA_FONT_EMWIDTH, NSERROR_INVALID, NSERROR_OK, plot_font_style::size, utf8_next(), and utf8_to_enc().

Here is the call graph for this function:

◆ amiga_nsfont_split()

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 
)
static

Find where to split a string to make it fit a width.

Parameters
fstylestyle for this text
stringUTF-8 string to measure
lengthlength of string
xwidth available
char_offsetupdated to offset in string of actual_x, [1..length]
actual_xupdated to x coordinate of character closest to x
Returns
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

Definition at line 274 of file font_bullet.c.

References ami_font_width_glyph(), ami_open_outline_font(), NSA_FONT_EMWIDTH, NSERROR_INVALID, NSERROR_OK, plot_font_style::size, utf8_next(), and utf8_to_enc().

Here is the call graph for this function:

◆ amiga_nsfont_text()

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

Definition at line 745 of file font_bullet.c.

References ami_font_plot_glyph(), ami_font_translate_smallcaps(), ami_open_outline_font(), amiga_nsfont_utf16_char_length(), plot_font_style::flags, FONTF_SMALLCAPS, NSA_FONT_EMWIDTH, NSERROR_OK, plot_font_style::size, and utf8_to_enc().

Here is the call graph for this function:

◆ amiga_nsfont_utf16_char_length()

static int amiga_nsfont_utf16_char_length ( const uint16 char1)
inlinestatic

Definition at line 148 of file font_bullet.c.

Referenced by ami_font_unicode_width(), ami_open_outline_font(), amiga_nsfont_decode_surrogate(), amiga_nsfont_position_in_string(), and amiga_nsfont_text().

Here is the caller graph for this function:

◆ amiga_nsfont_width()

static nserror amiga_nsfont_width ( const plot_font_style_t fstyle,
const char *  string,
size_t  length,
int *  width 
)
static

Definition at line 166 of file font_bullet.c.

References ami_font_unicode_width(), NSERROR_OK, and width.

Here is the call graph for this function:

Variable Documentation

◆ ami_diskfontlib_list

struct List ami_diskfontlib_list
static

Definition at line 137 of file font_bullet.c.

Referenced by ami_font_bullet_close(), ami_font_bullet_init(), and ami_font_open().

◆ ami_font_bullet_table

const struct ami_font_functions ami_font_bullet_table
Initial value:
= {
}
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)
Definition: font_bullet.c:745
static nserror amiga_nsfont_width(const plot_font_style_t *fstyle, const char *string, size_t length, int *width)
Definition: font_bullet.c:166
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.
Definition: font_bullet.c:274
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.
Definition: font_bullet.c:191

Definition at line 878 of file font_bullet.c.

Referenced by ami_font_bullet_init().

◆ glypharray

lwc_string* glypharray[0xffff+1]
static

◆ sc_table

const uint16 sc_table[]

Definition at line 68 of file font_bullet.c.

Referenced by ami_font_translate_smallcaps().