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