add API to set DPI

This commit is contained in:
Vincent Sanders 2014-10-13 02:34:10 +01:00
parent bfc7552d8d
commit 3fa0ed01c0
8 changed files with 44 additions and 22 deletions

View File

@ -25,8 +25,7 @@
#include "amiga/object.h"
#include "amiga/schedule.h"
#include "utils/nsoption.h"
#include "css/css.h"
#include "css/utils.h"
#include "desktop/browser.h"
#include "render/font.h"
#include "utils/log.h"
#include "utils/utf8.h"
@ -869,7 +868,7 @@ static void ami_font_cleanup(struct MinList *ami_font_list)
node->dtz_Node.ln_Name, curtime.Seconds));
DelObject(node);
}
}while(node=nnode);
} while(node=nnode);
/* reschedule to run in five minutes */
ami_schedule(300000, ami_font_cleanup, ami_font_list);
@ -882,7 +881,7 @@ void ami_font_setdevicedpi(int id)
ULONG ydpi = nsoption_int(screen_ydpi);
ULONG xdpi = nsoption_int(screen_ydpi);
nscss_screen_dpi = INTTOFIX(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))
{

View File

@ -93,8 +93,6 @@ fantasy.ttf => Fantasy
#define CACHE_MIN_SIZE (100 * 1024)
#define BOLD_WEIGHT 700
extern css_fixed nscss_screen_dpi;
extern unsigned long atari_plot_flags;
extern int atari_plot_vdi_handle;
@ -245,11 +243,11 @@ static void ft_fill_scalar(const plot_font_style_t *fstyle, FTC_Scaler srec)
srec->width = srec->height = (fstyle->size * 64) / FONT_SIZE_SCALE;
srec->pixel = 0;
/* calculate x/y resolution, when nscss_screen_dpi isn't available */
/* 72 is an good value. */
/* TODO: because nscss_screen_dpi is to large, calculate that value */
/* by VDI values. */
srec->x_res = srec->y_res = 72; // FIXTOINT(nscss_screen_dpi);
/* calculate x/y resolution, when browser_get_dpi() isn't available */
/* 72 is an good value. */
/* TODO: because browser_get_dpi() is to large, calculate that value */
/* by VDI values. */
srec->x_res = srec->y_res = 72; // browser_get_dpi();
}
static FT_Glyph ft_getglyph(const plot_font_style_t *fstyle, uint32_t ucs4)

View File

@ -22,10 +22,10 @@
#import "cocoa/plotter.h"
#import "cocoa/bitmap.h"
#import "desktop/browser.h"
#import "desktop/plotters.h"
#import "desktop/plot_style.h"
#import "utils/log.h"
#import "css/utils.h"
static void cocoa_plot_render_path(NSBezierPath *path,const plot_style_t *pstyle);
static void cocoa_plot_path_set_stroke_pattern(NSBezierPath *path,const plot_style_t *pstyle);
@ -323,7 +323,7 @@ void cocoa_update_scale_factor( void )
const CGFloat scale = [[NSScreen mainScreen] userSpaceScaleFactor];
cocoa_scale_factor = scale == 1.0 ? 1.0 : 1.0 / scale;
cocoa_half_pixel = 0.5 * cocoa_scale_factor;
nscss_screen_dpi = FLTTOFIX( points_per_inch * scale );
browser_set_dpi( points_per_inch * scale );
}
static inline void cocoa_center_pixel( bool x, bool y )

View File

@ -53,6 +53,7 @@
#include "desktop/scrollbar.h"
#include "desktop/selection.h"
#include "desktop/plotters.h"
#include "css/utils.h"
#include "javascript/js.h"
@ -3124,3 +3125,17 @@ bool browser_window_stop_available(struct browser_window *bw)
(content_get_status(bw->current_content) !=
CONTENT_STATUS_DONE))));
}
/* exported interface documented in browser.h */
nserror browser_set_dpi(int dpi)
{
nscss_screen_dpi = INTTOFIX(dpi);
return NSERROR_OK;
}
/* exported interface documented in browser.h */
int browser_get_dpi(void)
{
return FIXTOINT(nscss_screen_dpi);
}

View File

@ -460,4 +460,18 @@ nserror browser_window_debug_dump(struct browser_window *bw, FILE *f, enum conte
void theme_install_start(struct hlcache_handle *c);
#endif
/**
* Set the DPI of the browser.
*
* \param dpi The DPI to set.
*/
nserror browser_set_dpi(int dpi);
/**
* Get the browser DPI.
*
* \return The DPI in use.
*/
int browser_get_dpi(void);
#endif

View File

@ -27,10 +27,9 @@
#include "utils/utf8.h"
#include "utils/log.h"
#include "utils/nsoption.h"
#include "css/css.h"
#include "css/utils.h"
#include "render/font.h"
#include "desktop/gui.h"
#include "desktop/browser.h"
#include "framebuffer/gui.h"
#include "framebuffer/font.h"
@ -378,7 +377,7 @@ static void fb_fill_scalar(const plot_font_style_t *fstyle, FTC_Scaler srec)
srec->width = srec->height = (fstyle->size * 64) / FONT_SIZE_SCALE;
srec->pixel = 0;
srec->x_res = srec->y_res = FIXTOINT(nscss_screen_dpi);
srec->x_res = srec->y_res = browser_get_dpi();
}
FT_Glyph fb_getglyph(const plot_font_style_t *fstyle, uint32_t ucs4)

View File

@ -55,7 +55,6 @@
#include "desktop/sslcert_viewer.h"
#include "desktop/textinput.h"
#include "desktop/tree.h"
#include "css/utils.h"
#include "render/form.h"
#include "utils/filepath.h"
#include "utils/log.h"
@ -412,10 +411,8 @@ static nserror nsgtk_init(int argc, char** argv, char **respath)
* find that out here, rather than when we create a first browser
* window.
*/
nscss_screen_dpi = FLTTOFIX(gdk_screen_get_resolution(
gdk_screen_get_default()));
LOG(("Set CSS DPI to %f", FIXTOFLT(nscss_screen_dpi)));
browser_set_dpi(gdk_screen_get_resolution(gdk_screen_get_default()));
LOG(("Set CSS DPI to %d", browser_get_dpi()));
if (nsgtk_history_init(glade_file_location->history) == false)
die("Unable to initialise history window.\n");

View File

@ -1219,7 +1219,7 @@ static HWND nsws_window_create(struct gui_window *gw)
/* set the gui window associated with this browser */
SetProp(hwnd, TEXT("GuiWnd"), (HANDLE)gw);
nscss_screen_dpi = get_window_dpi(hwnd);
browser_set_dpi(get_window_dpi(hwnd));
if ((nsoption_int(window_width) >= 100) &&
(nsoption_int(window_height) >= 100) &&