NetSurf
font.c
Go to the documentation of this file.
1/*
2 * Copyright 2008 - 2016 Chris Young <chris@unsatisfactorysoftware.co.uk>
3 *
4 * This file is part of NetSurf, http://www.netsurf-browser.org/
5 *
6 * NetSurf is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * NetSurf is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include "amiga/os3support.h"
20
21#include <proto/diskfont.h>
22#include <proto/exec.h>
23#include <proto/graphics.h>
24
25#include "utils/log.h"
26#include "utils/nsoption.h"
27#include "netsurf/browser.h"
28#include "netsurf/layout.h"
29
30#include "amiga/font.h"
31#include "amiga/font_bullet.h"
32#include "amiga/font_diskfont.h"
33#include "amiga/font_scan.h"
34
35static ULONG ami_devicedpi = 72;
36static ULONG ami_xdpi = 72;
37
39
41{
42 return (ami_xdpi << 16) | ami_devicedpi;
43}
44
46{
47 return ami_xdpi;
48}
49
51{
52 DisplayInfoHandle dih;
53 struct DisplayInfo dinfo;
54
55 ULONG ydpi = nsoption_int(screen_ydpi);
56 ULONG xdpi = nsoption_int(screen_ydpi);
57 browser_set_dpi(nsoption_int(screen_ydpi));
58
59 if(id && (nsoption_int(monitor_aspect_x) != 0) && (nsoption_int(monitor_aspect_y) != 0))
60 {
61 if((dih = FindDisplayInfo(id)))
62 {
63 if(GetDisplayInfoData(dih, &dinfo, sizeof(struct DisplayInfo),
64 DTAG_DISP, 0))
65 {
66 int xres = dinfo.Resolution.x;
67 int yres = dinfo.Resolution.y;
68
69 if((nsoption_int(monitor_aspect_x) != 4) || (nsoption_int(monitor_aspect_y) != 3))
70 {
71 /* AmigaOS sees 4:3 modes as square in the DisplayInfo database,
72 * so we correct other modes to "4:3 equiv" here. */
73 xres = (xres * nsoption_int(monitor_aspect_x)) / 4;
74 yres = (yres * nsoption_int(monitor_aspect_y)) / 3;
75 }
76
77 xdpi = (yres * ydpi) / xres;
78
79 NSLOG(netsurf, INFO,
80 "XDPI = %ld, YDPI = %ld (DisplayInfo resolution %d x %d, corrected %d x %d)",
81 xdpi,
82 ydpi,
83 dinfo.Resolution.x,
84 dinfo.Resolution.y,
85 xres,
86 yres);
87 }
88 }
89 }
90
91 ami_xdpi = xdpi;
92 ami_devicedpi = (xdpi << 16) | ydpi;
93}
94
95/* The below are simple font routines which should not be used for page rendering */
96
97struct TextFont *ami_font_open_disk_font(struct TextAttr *tattr)
98{
99 struct TextFont *tfont = OpenDiskFont(tattr);
100 return tfont;
101}
102
103void ami_font_close_disk_font(struct TextFont *tfont)
104{
105 CloseFont(tfont);
106}
107
108/* Font initialisation */
110{
111 if(nsoption_bool(bitmap_fonts) == false) {
112#ifdef __amigaos4__
113 nsoption_setnull_charp(font_sans, (char *)strdup("DejaVu Sans"));
114 nsoption_setnull_charp(font_serif, (char *)strdup("DejaVu Serif"));
115 nsoption_setnull_charp(font_mono, (char *)strdup("DejaVu Sans Mono"));
116 nsoption_setnull_charp(font_cursive, (char *)strdup("DejaVu Sans"));
117 nsoption_setnull_charp(font_fantasy, (char *)strdup("DejaVu Serif"));
118#else
119 /* Default CG fonts for OS3 - these work with use_diskfont both on and off,
120 however they are slow in both cases. The bitmap fonts don't work when
121 use_diskfont is off. */
122 nsoption_setnull_charp(font_sans, (char *)strdup("CGTriumvirate"));
123 nsoption_setnull_charp(font_serif, (char *)strdup("CGTimes"));
124 nsoption_setnull_charp(font_mono, (char *)strdup("LetterGothic"));
125 nsoption_setnull_charp(font_cursive, (char *)strdup("CGTriumvirate"));
126 nsoption_setnull_charp(font_fantasy, (char *)strdup("CGTimes"));
127#endif
129 } else {
130 nsoption_setnull_charp(font_sans, (char *)strdup("helvetica"));
131 nsoption_setnull_charp(font_serif, (char *)strdup("times"));
132 nsoption_setnull_charp(font_mono, (char *)strdup("topaz"));
133 nsoption_setnull_charp(font_cursive, (char *)strdup("garnet"));
134 nsoption_setnull_charp(font_fantasy, (char *)strdup("emerald"));
135
137 }
138}
139
141{
142 if(nsoption_bool(bitmap_fonts) == false) {
144 } else {
146 }
147}
148
149/* Stub entry points */
151 const char *string, size_t length,
152 int *width)
153{
154 if(__builtin_expect(ami_nsfont == NULL, 0)) return false;
155 return ami_nsfont->width(fstyle, string, length, width);
156}
157
159 const char *string, size_t length,
160 int x, size_t *char_offset, int *actual_x)
161{
162 if(__builtin_expect(ami_nsfont == NULL, 0)) return false;
163 return ami_nsfont->posn(fstyle, string, length, x, char_offset, actual_x);
164}
165
167 const char *string, size_t length,
168 int x, size_t *char_offset, int *actual_x)
169{
170 if(__builtin_expect(ami_nsfont == NULL, 0)) return false;
171 return ami_nsfont->split(fstyle, string, length, x, char_offset, actual_x);
172}
173
176 .position = ami_font_position,
177 .split = ami_font_split,
178};
179
nserror
Enumeration of error codes.
Definition: errors.h:29
void ami_font_bullet_fini(void)
Definition: font_bullet.c:906
void ami_font_bullet_init(void)
Definition: font_bullet.c:891
void ami_font_diskfont_init(void)
void ami_font_diskfont_fini(void)
static ULONG ami_devicedpi
Definition: font.c:35
static nserror ami_font_position(const plot_font_style_t *fstyle, const char *string, size_t length, int x, size_t *char_offset, int *actual_x)
Definition: font.c:158
ULONG ami_font_dpi_get_devicedpi(void)
Definition: font.c:40
struct ami_font_functions * ami_nsfont
Definition: font.c:38
static ULONG ami_xdpi
Definition: font.c:36
ULONG ami_font_dpi_get_xdpi(void)
Definition: font.c:45
struct TextFont * ami_font_open_disk_font(struct TextAttr *tattr)
Definition: font.c:97
void ami_font_close_disk_font(struct TextFont *tfont)
Definition: font.c:103
void ami_font_init(void)
Definition: font.c:109
struct gui_layout_table * ami_layout_table
Definition: font.c:180
static struct gui_layout_table layout_table
Definition: font.c:174
void ami_font_setdevicedpi(int id)
Definition: font.c:50
void ami_font_fini(void)
Definition: font.c:140
static nserror ami_font_width(const plot_font_style_t *fstyle, const char *string, size_t length, int *width)
Definition: font.c:150
static nserror ami_font_split(const plot_font_style_t *fstyle, const char *string, size_t length, int x, size_t *char_offset, int *actual_x)
Definition: font.c:166
Browser interfaces.
nserror browser_set_dpi(int dpi)
Set the DPI of the browser.
Definition: browser.c:32
Interface to platform-specific layout operation table.
#define NSLOG(catname, level, logmsg, args...)
Definition: log.h:116
Minimal compatibility header for AmigaOS 3.
int width
Definition: gui.c:161
nserror(* posn)(const plot_font_style_t *fstyle, const char *string, size_t length, int x, size_t *char_offset, int *actual_x)
Definition: font.h:45
nserror(* width)(const plot_font_style_t *fstyle, const char *string, size_t length, int *width)
Definition: font.h:41
nserror(* split)(const plot_font_style_t *fstyle, const char *string, size_t length, int x, size_t *char_offset, int *actual_x)
Definition: font.h:49
nserror(* width)(const struct plot_font_style *fstyle, const char *string, size_t length, int *width)
Measure the width of a string.
Definition: layout.h:49
Font style for plotting.
Definition: plot_style.h:111
Option reading and saving interface.
#define nsoption_setnull_charp(OPTION, VALUE)
set string option in default table if currently unset
Definition: nsoption.h:380
#define nsoption_int(OPTION)
Get the value of an integer option.
Definition: nsoption.h:317
#define nsoption_bool(OPTION)
Get the value of a boolean option.
Definition: nsoption.h:308