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 if(nsoption_bool(bitmap_fonts) == true) {
56 NSLOG(netsurf, INFO,
57 "WARNING: Using diskfont.library for text. Forcing DPI to 72.");
58 nsoption_set_int(screen_ydpi, 72);
59 }
60
61 ULONG ydpi = nsoption_int(screen_ydpi);
62 ULONG xdpi = nsoption_int(screen_ydpi);
63 browser_set_dpi(nsoption_int(screen_ydpi));
64
65 if(id && (nsoption_int(monitor_aspect_x) != 0) && (nsoption_int(monitor_aspect_y) != 0))
66 {
67 if((dih = FindDisplayInfo(id)))
68 {
69 if(GetDisplayInfoData(dih, &dinfo, sizeof(struct DisplayInfo),
70 DTAG_DISP, 0))
71 {
72 int xres = dinfo.Resolution.x;
73 int yres = dinfo.Resolution.y;
74
75 if((nsoption_int(monitor_aspect_x) != 4) || (nsoption_int(monitor_aspect_y) != 3))
76 {
77 /* AmigaOS sees 4:3 modes as square in the DisplayInfo database,
78 * so we correct other modes to "4:3 equiv" here. */
79 xres = (xres * nsoption_int(monitor_aspect_x)) / 4;
80 yres = (yres * nsoption_int(monitor_aspect_y)) / 3;
81 }
82
83 xdpi = (yres * ydpi) / xres;
84
85 NSLOG(netsurf, INFO,
86 "XDPI = %ld, YDPI = %ld (DisplayInfo resolution %d x %d, corrected %d x %d)",
87 xdpi,
88 ydpi,
89 dinfo.Resolution.x,
90 dinfo.Resolution.y,
91 xres,
92 yres);
93 }
94 }
95 }
96
97 ami_xdpi = xdpi;
98 ami_devicedpi = (xdpi << 16) | ydpi;
99}
100
101/* The below are simple font routines which should not be used for page rendering */
102
103struct TextFont *ami_font_open_disk_font(struct TextAttr *tattr)
104{
105 struct TextFont *tfont = OpenDiskFont(tattr);
106 return tfont;
107}
108
109void ami_font_close_disk_font(struct TextFont *tfont)
110{
111 CloseFont(tfont);
112}
113
114/* Font initialisation */
116{
117 if(nsoption_bool(bitmap_fonts) == false) {
119 } else {
121 }
122}
123
125{
126 if(nsoption_bool(bitmap_fonts) == false) {
128 } else {
130 }
131}
132
133/* Stub entry points */
135 const char *string, size_t length,
136 int *width)
137{
138 if(__builtin_expect(ami_nsfont == NULL, 0)) return false;
139 return ami_nsfont->width(fstyle, string, length, width);
140}
141
143 const char *string, size_t length,
144 int x, size_t *char_offset, int *actual_x)
145{
146 if(__builtin_expect(ami_nsfont == NULL, 0)) return false;
147 return ami_nsfont->posn(fstyle, string, length, x, char_offset, actual_x);
148}
149
151 const char *string, size_t length,
152 int x, size_t *char_offset, int *actual_x)
153{
154 if(__builtin_expect(ami_nsfont == NULL, 0)) return false;
155 return ami_nsfont->split(fstyle, string, length, x, char_offset, actual_x);
156}
157
160 .position = ami_font_position,
161 .split = ami_font_split,
162};
163
nserror
Enumeration of error codes.
Definition: errors.h:29
void ami_font_bullet_fini(void)
Definition: font_bullet.c:900
void ami_font_bullet_init(void)
Definition: font_bullet.c:885
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:142
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:103
void ami_font_close_disk_font(struct TextFont *tfont)
Definition: font.c:109
void ami_font_init(void)
Definition: font.c:115
struct gui_layout_table * ami_layout_table
Definition: font.c:164
static struct gui_layout_table layout_table
Definition: font.c:158
void ami_font_setdevicedpi(int id)
Definition: font.c:50
void ami_font_fini(void)
Definition: font.c:124
static nserror ami_font_width(const plot_font_style_t *fstyle, const char *string, size_t length, int *width)
Definition: font.c:134
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:150
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_int(OPTION)
Get the value of an integer option.
Definition: nsoption.h:317
#define nsoption_set_int(OPTION, VALUE)
set an integer option in the default table
Definition: nsoption.h:352
#define nsoption_bool(OPTION)
Get the value of a boolean option.
Definition: nsoption.h:308