summaryrefslogtreecommitdiff
path: root/frontends/amiga/font.c
blob: 63172623f6439bad0d98e7812d781efade1e2d1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*
 * Copyright 2008 - 2016 Chris Young <chris@unsatisfactorysoftware.co.uk>
 *
 * This file is part of NetSurf, http://www.netsurf-browser.org/
 *
 * NetSurf is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 2 of the License.
 *
 * NetSurf is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "amiga/os3support.h"

#include <proto/diskfont.h>
#include <proto/exec.h>
#include <proto/graphics.h>

#include "utils/log.h"
#include "utils/nsoption.h"
#include "netsurf/browser_window.h"
#include "netsurf/layout.h"

#include "amiga/font.h"
#include "amiga/font_bullet.h"
#include "amiga/font_diskfont.h"
#include "amiga/font_scan.h"

static ULONG ami_devicedpi = 72;
static ULONG ami_xdpi = 72;

ULONG ami_font_dpi_get_devicedpi(void)
{
	return ami_devicedpi;
}

ULONG ami_font_dpi_get_xdpi(void)
{
	return ami_xdpi;
}

void ami_font_setdevicedpi(int id)
{
	DisplayInfoHandle dih;
	struct DisplayInfo dinfo;

	if(nsoption_bool(bitmap_fonts) == true) {
		NSLOG(netsurf, INFO,
		      "WARNING: Using diskfont.library for text. Forcing DPI to 72.");
		nsoption_set_int(screen_ydpi, 72);
	}

	ULONG ydpi = nsoption_int(screen_ydpi);
	ULONG xdpi = nsoption_int(screen_ydpi);
	browser_set_dpi(nsoption_int(screen_ydpi));

	if(id && (nsoption_int(monitor_aspect_x) != 0) && (nsoption_int(monitor_aspect_y) != 0))
	{
		if((dih = FindDisplayInfo(id)))
		{
			if(GetDisplayInfoData(dih, &dinfo, sizeof(struct DisplayInfo),
				DTAG_DISP, 0))
			{
				int xres = dinfo.Resolution.x;
				int yres = dinfo.Resolution.y;

				if((nsoption_int(monitor_aspect_x) != 4) || (nsoption_int(monitor_aspect_y) != 3))
				{
					/* AmigaOS sees 4:3 modes as square in the DisplayInfo database,
					 * so we correct other modes to "4:3 equiv" here. */
					xres = (xres * nsoption_int(monitor_aspect_x)) / 4;
					yres = (yres * nsoption_int(monitor_aspect_y)) / 3;
				}

				xdpi = (yres * ydpi) / xres;

				NSLOG(netsurf, INFO,
				      "XDPI = %ld, YDPI = %ld (DisplayInfo resolution %d x %d, corrected %d x %d)",
				      xdpi,
				      ydpi,
				      dinfo.Resolution.x,
				      dinfo.Resolution.y,
				      xres,
				      yres);
			}
		}
	}

	ami_xdpi = xdpi;
	ami_devicedpi = (xdpi << 16) | ydpi;
}

/* The below are simple font routines which should not be used for page rendering */

struct TextFont *ami_font_open_disk_font(struct TextAttr *tattr)
{
	struct TextFont *tfont = OpenDiskFont(tattr);
	return tfont;
}

void ami_font_close_disk_font(struct TextFont *tfont)
{
	CloseFont(tfont);
}

/* Font initialisation */
void ami_font_init(void)
{
	if(nsoption_bool(bitmap_fonts) == false) {
		ami_font_bullet_init();
	} else {
		ami_font_diskfont_init();
	}
}

void ami_font_fini(void)
{
	if(nsoption_bool(bitmap_fonts) == false) {
		ami_font_bullet_fini();
	} else {
		ami_font_diskfont_fini();
	}
}

/* Stub entry points */
static nserror ami_font_width(const plot_font_style_t *fstyle,
		const char *string, size_t length,
		int *width)
{
	if(__builtin_expect(ami_nsfont == NULL, 0)) return false;
	return ami_nsfont->width(fstyle, string, length, width);
}

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)
{
	if(__builtin_expect(ami_nsfont == NULL, 0)) return false;
	return ami_nsfont->posn(fstyle, string, length, x, char_offset, actual_x);
}

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)
{
	if(__builtin_expect(ami_nsfont == NULL, 0)) return false;
	return ami_nsfont->split(fstyle, string, length, x, char_offset, actual_x);
}

static struct gui_layout_table layout_table = {
	.width = ami_font_width,
	.position = ami_font_position,
	.split = ami_font_split,
};

struct gui_layout_table *ami_layout_table = &layout_table;