mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-12-18 18:23:25 +03:00
update cocoa frontend to use font layout table
This commit is contained in:
parent
d8b6de50d6
commit
f90ed33501
@ -25,6 +25,7 @@
|
||||
#import "cocoa/selection.h"
|
||||
#import "cocoa/fetch.h"
|
||||
#import "cocoa/bitmap.h"
|
||||
#import "cocoa/font.h"
|
||||
|
||||
#import "utils/filename.h"
|
||||
#import "utils/log.h"
|
||||
@ -235,6 +236,7 @@ int main( int argc, char **argv )
|
||||
.fetch = cocoa_fetch_table,
|
||||
.search = cocoa_search_table,
|
||||
.bitmap = cocoa_bitmap_table,
|
||||
.layout = cocoa_layout_table,
|
||||
};
|
||||
|
||||
error = netsurf_register(&cocoa_table);
|
||||
|
@ -21,6 +21,8 @@
|
||||
|
||||
#import "desktop/plot_style.h"
|
||||
|
||||
void cocoa_draw_string( CGFloat x, CGFloat y, const char *bytes, size_t length, const plot_font_style_t *style );
|
||||
void cocoa_draw_string( CGFloat x, CGFloat y, const char *bytes, size_t length, const struct plot_font_style *style );
|
||||
|
||||
struct gui_layout_table *cocoa_layout_table;
|
||||
|
||||
#endif
|
||||
|
51
cocoa/font.m
51
cocoa/font.m
@ -38,21 +38,24 @@ static NSDictionary *cocoa_font_attributes( const plot_font_style_t *style );
|
||||
static NSTextStorage *cocoa_text_storage = nil;
|
||||
static NSTextContainer *cocoa_text_container = nil;
|
||||
|
||||
static bool nsfont_width(const plot_font_style_t *style,
|
||||
const char *string, size_t length,
|
||||
int *width)
|
||||
static nserror cocoa_font_width(const plot_font_style_t *style,
|
||||
const char *string, size_t length,
|
||||
int *width)
|
||||
{
|
||||
NSLayoutManager *layout = cocoa_prepare_layout_manager( string, length, style );
|
||||
NSLayoutManager *layout;
|
||||
layout = cocoa_prepare_layout_manager( string, length, style );
|
||||
*width = cocoa_layout_width( layout );
|
||||
return true;
|
||||
return NSERROR_OK;
|
||||
}
|
||||
|
||||
static bool nsfont_position_in_string(const plot_font_style_t *style,
|
||||
const char *string, size_t length,
|
||||
int x, size_t *char_offset, int *actual_x)
|
||||
static nserror cocoa_font_position(const plot_font_style_t *style,
|
||||
const char *string, size_t length,
|
||||
int x, size_t *char_offset, int *actual_x)
|
||||
{
|
||||
NSLayoutManager *layout = cocoa_prepare_layout_manager( string, length, style );
|
||||
if (layout == nil) return false;
|
||||
if (layout == nil) {
|
||||
return NSERROR_BAD_PARAMETER;
|
||||
}
|
||||
|
||||
NSUInteger glyphIndex = cocoa_glyph_for_location( layout, x );
|
||||
NSUInteger chars = [layout characterIndexForGlyphAtIndex: glyphIndex];
|
||||
@ -61,17 +64,17 @@ static bool nsfont_position_in_string(const plot_font_style_t *style,
|
||||
else *char_offset = cocoa_bytes_for_characters( string, chars );
|
||||
|
||||
*actual_x = cocoa_pt_to_px( NSMaxX( [layout boundingRectForGlyphRange: NSMakeRange( glyphIndex - 1, 1 )
|
||||
inTextContainer: cocoa_text_container] ) );
|
||||
inTextContainer: cocoa_text_container] ) );
|
||||
|
||||
return true;
|
||||
return NSERROR_OK;
|
||||
}
|
||||
|
||||
static bool nsfont_split(const plot_font_style_t *style,
|
||||
const char *string, size_t length,
|
||||
int x, size_t *char_offset, int *actual_x)
|
||||
static nserror cocoa_font_split(const plot_font_style_t *style,
|
||||
const char *string, size_t length,
|
||||
int x, size_t *char_offset, int *actual_x)
|
||||
{
|
||||
NSLayoutManager *layout = cocoa_prepare_layout_manager( string, length, style );
|
||||
if (layout == nil) return false;
|
||||
if (layout == nil) return NSERROR_BAD_PARAMETER;
|
||||
|
||||
NSUInteger glyphIndex = cocoa_glyph_for_location( layout, x );
|
||||
NSUInteger chars = [layout characterIndexForGlyphAtIndex: glyphIndex];
|
||||
@ -79,7 +82,7 @@ static bool nsfont_split(const plot_font_style_t *style,
|
||||
if (chars >= [cocoa_text_storage length]) {
|
||||
*char_offset = length;
|
||||
*actual_x = cocoa_layout_width( layout );
|
||||
return true;
|
||||
return NSERROR_OK;
|
||||
}
|
||||
|
||||
|
||||
@ -87,21 +90,25 @@ static bool nsfont_split(const plot_font_style_t *style,
|
||||
if (chars == NSNotFound) {
|
||||
*char_offset = 0;
|
||||
*actual_x = 0;
|
||||
return true;
|
||||
return NSERROR_OK;
|
||||
}
|
||||
|
||||
*char_offset = cocoa_bytes_for_characters( string, chars );
|
||||
*actual_x = cocoa_layout_width_chars( layout, chars );
|
||||
|
||||
return true;
|
||||
return NSERROR_OK;
|
||||
}
|
||||
|
||||
const struct font_functions nsfont = {
|
||||
nsfont_width,
|
||||
nsfont_position_in_string,
|
||||
nsfont_split
|
||||
|
||||
static struct gui_layout_table layout_table = {
|
||||
.width = cocoa_font_width,
|
||||
.position = fb_font_position,
|
||||
.split = fb_font_split,
|
||||
};
|
||||
|
||||
struct gui_layout_table *cocoa_layout_table = &layout_table;
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
void cocoa_draw_string( CGFloat x, CGFloat y, const char *bytes, size_t length, const plot_font_style_t *style )
|
||||
|
Loading…
Reference in New Issue
Block a user