mirror of
https://github.com/netsurf-browser/netsurf
synced 2025-01-03 17:54:33 +03:00
Refactor text plotter and other font functions to remove dependency on CSS.
svn path=/trunk/netsurf/; revision=8641
This commit is contained in:
parent
1930989f8c
commit
2565a37a52
@ -9,7 +9,7 @@ S_CONTENT := content.c fetch.c fetchcache.c urldb.c \
|
|||||||
fetchers/fetch_curl.c fetchers/fetch_data.c
|
fetchers/fetch_curl.c fetchers/fetch_data.c
|
||||||
S_CSS := css.c css_enum.c parser.c ruleset.c scanner.c
|
S_CSS := css.c css_enum.c parser.c ruleset.c scanner.c
|
||||||
S_RENDER := box.c box_construct.c box_normalise.c directory.c \
|
S_RENDER := box.c box_construct.c box_normalise.c directory.c \
|
||||||
form.c html.c html_redraw.c hubbub_binding.c imagemap.c \
|
font.c form.c html.c html_redraw.c hubbub_binding.c imagemap.c \
|
||||||
layout.c list.c loosen.c table.c textplain.c
|
layout.c list.c loosen.c table.c textplain.c
|
||||||
S_UTILS := base64.c filename.c hashtable.c locale.c messages.c talloc.c \
|
S_UTILS := base64.c filename.c hashtable.c locale.c messages.c talloc.c \
|
||||||
url.c utf8.c utils.c useragent.c
|
url.c utf8.c utils.c useragent.c
|
||||||
|
102
amiga/font.c
102
amiga/font.c
@ -36,22 +36,22 @@
|
|||||||
#include <proto/utility.h>
|
#include <proto/utility.h>
|
||||||
#include "utils/utils.h"
|
#include "utils/utils.h"
|
||||||
|
|
||||||
static struct OutlineFont *of[CSS_FONT_FAMILY_NOT_SET];
|
static struct OutlineFont *of[PLOT_FONT_FAMILY_COUNT];
|
||||||
static struct OutlineFont *ofb[CSS_FONT_FAMILY_NOT_SET];
|
static struct OutlineFont *ofb[PLOT_FONT_FAMILY_COUNT];
|
||||||
static struct OutlineFont *ofi[CSS_FONT_FAMILY_NOT_SET];
|
static struct OutlineFont *ofi[PLOT_FONT_FAMILY_COUNT];
|
||||||
static struct OutlineFont *ofbi[CSS_FONT_FAMILY_NOT_SET];
|
static struct OutlineFont *ofbi[PLOT_FONT_FAMILY_COUNT];
|
||||||
|
|
||||||
struct OutlineFont *ami_open_outline_font(const struct css_style *style);
|
struct OutlineFont *ami_open_outline_font(const plot_font_style_t *fstyle);
|
||||||
|
|
||||||
static bool nsfont_width(const struct css_style *style,
|
static bool nsfont_width(const plot_font_style_t *fstyle,
|
||||||
const char *string, size_t length,
|
const char *string, size_t length,
|
||||||
int *width);
|
int *width);
|
||||||
|
|
||||||
static bool nsfont_position_in_string(const struct css_style *style,
|
static bool nsfont_position_in_string(const plot_font_style_t *fstyle,
|
||||||
const char *string, size_t length,
|
const char *string, size_t length,
|
||||||
int x, size_t *char_offset, int *actual_x);
|
int x, size_t *char_offset, int *actual_x);
|
||||||
|
|
||||||
static bool nsfont_split(const struct css_style *style,
|
static bool nsfont_split(const plot_font_style_t *fstyle,
|
||||||
const char *string, size_t length,
|
const char *string, size_t length,
|
||||||
int x, size_t *char_offset, int *actual_x);
|
int x, size_t *char_offset, int *actual_x);
|
||||||
|
|
||||||
@ -61,13 +61,13 @@ const struct font_functions nsfont = {
|
|||||||
nsfont_split
|
nsfont_split
|
||||||
};
|
};
|
||||||
|
|
||||||
bool nsfont_width(const struct css_style *style,
|
bool nsfont_width(const plot_font_style_t *fstyle,
|
||||||
const char *string, size_t length,
|
const char *string, size_t length,
|
||||||
int *width)
|
int *width)
|
||||||
{
|
{
|
||||||
struct TextFont *tfont;
|
struct TextFont *tfont;
|
||||||
|
|
||||||
*width = ami_unicode_text(NULL,string,length,style,0,0,0);
|
*width = ami_unicode_text(NULL,string,length,fstyle,0,0);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -75,8 +75,7 @@ bool nsfont_width(const struct css_style *style,
|
|||||||
/**
|
/**
|
||||||
* Find the position in a string where an x coordinate falls.
|
* Find the position in a string where an x coordinate falls.
|
||||||
*
|
*
|
||||||
* \param style css_style for this text, with style->font_size.size ==
|
* \param fstyle style for this text
|
||||||
* CSS_FONT_SIZE_LENGTH
|
|
||||||
* \param string UTF-8 string to measure
|
* \param string UTF-8 string to measure
|
||||||
* \param length length of string
|
* \param length length of string
|
||||||
* \param x x coordinate to search for
|
* \param x x coordinate to search for
|
||||||
@ -85,7 +84,7 @@ bool nsfont_width(const struct css_style *style,
|
|||||||
* \return true on success, false on error and error reported
|
* \return true on success, false on error and error reported
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool nsfont_position_in_string(const struct css_style *style,
|
bool nsfont_position_in_string(const plot_font_style_t *fstyle,
|
||||||
const char *string, size_t length,
|
const char *string, size_t length,
|
||||||
int x, size_t *char_offset, int *actual_x)
|
int x, size_t *char_offset, int *actual_x)
|
||||||
{
|
{
|
||||||
@ -103,7 +102,7 @@ bool nsfont_position_in_string(const struct css_style *style,
|
|||||||
if(utf8_to_enc(string,"UTF-16",length,(char **)&utf16) != UTF8_CONVERT_OK) return false;
|
if(utf8_to_enc(string,"UTF-16",length,(char **)&utf16) != UTF8_CONVERT_OK) return false;
|
||||||
outf16 = utf16;
|
outf16 = utf16;
|
||||||
|
|
||||||
if(!(ofont = ami_open_outline_font(style))) return false;
|
if(!(ofont = ami_open_outline_font(fstyle))) return false;
|
||||||
|
|
||||||
*char_offset = length;
|
*char_offset = length;
|
||||||
|
|
||||||
@ -154,8 +153,7 @@ bool nsfont_position_in_string(const struct css_style *style,
|
|||||||
/**
|
/**
|
||||||
* Find where to split a string to make it fit a width.
|
* Find where to split a string to make it fit a width.
|
||||||
*
|
*
|
||||||
* \param style css_style for this text, with style->font_size.size ==
|
* \param fstyle style for this text
|
||||||
* CSS_FONT_SIZE_LENGTH
|
|
||||||
* \param string UTF-8 string to measure
|
* \param string UTF-8 string to measure
|
||||||
* \param length length of string
|
* \param length length of string
|
||||||
* \param x width available
|
* \param x width available
|
||||||
@ -168,7 +166,7 @@ bool nsfont_position_in_string(const struct css_style *style,
|
|||||||
* char_offset == length]
|
* char_offset == length]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool nsfont_split(const struct css_style *style,
|
bool nsfont_split(const plot_font_style_t *fstyle,
|
||||||
const char *string, size_t length,
|
const char *string, size_t length,
|
||||||
int x, size_t *char_offset, int *actual_x)
|
int x, size_t *char_offset, int *actual_x)
|
||||||
{
|
{
|
||||||
@ -185,7 +183,7 @@ bool nsfont_split(const struct css_style *style,
|
|||||||
len = utf8_bounded_length(string, length);
|
len = utf8_bounded_length(string, length);
|
||||||
if(utf8_to_enc((char *)string,"UTF-16",length,(char **)&utf16) != UTF8_CONVERT_OK) return false;
|
if(utf8_to_enc((char *)string,"UTF-16",length,(char **)&utf16) != UTF8_CONVERT_OK) return false;
|
||||||
outf16 = utf16;
|
outf16 = utf16;
|
||||||
if(!(ofont = ami_open_outline_font(style))) return false;
|
if(!(ofont = ami_open_outline_font(fstyle))) return false;
|
||||||
|
|
||||||
*char_offset = 0;
|
*char_offset = 0;
|
||||||
|
|
||||||
@ -235,52 +233,42 @@ bool nsfont_split(const struct css_style *style,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct OutlineFont *ami_open_outline_font(const struct css_style *style)
|
struct OutlineFont *ami_open_outline_font(const plot_font_style_t *fstyle)
|
||||||
{
|
{
|
||||||
struct OutlineFont *ofont;
|
struct OutlineFont *ofont;
|
||||||
char *fontname;
|
char *fontname;
|
||||||
WORD ysize;
|
WORD ysize;
|
||||||
int tstyle = 0;
|
int tstyle = 0;
|
||||||
|
|
||||||
switch(style->font_style)
|
if ((fstyle->flags & FONTF_ITALIC) || (fstyle->flags & FONTF_OBLIQUE))
|
||||||
{
|
tstyle += NSA_ITALIC;
|
||||||
case CSS_FONT_STYLE_ITALIC:
|
|
||||||
case CSS_FONT_STYLE_OBLIQUE:
|
|
||||||
tstyle += NSA_ITALIC;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch(style->font_weight)
|
if (fstyle->weight >= 700)
|
||||||
{
|
tstyle += NSA_BOLD;
|
||||||
case CSS_FONT_WEIGHT_BOLD:
|
|
||||||
case CSS_FONT_WEIGHT_BOLDER:
|
|
||||||
tstyle += NSA_BOLD;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch(tstyle)
|
switch(tstyle)
|
||||||
{
|
{
|
||||||
case NSA_ITALIC:
|
case NSA_ITALIC:
|
||||||
if(ofi[style->font_family]) ofont = ofi[style->font_family];
|
if(ofi[fstyle->family]) ofont = ofi[fstyle->family];
|
||||||
else ofont = of[style->font_family];
|
else ofont = of[fstyle->family];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NSA_BOLD:
|
case NSA_BOLD:
|
||||||
if(ofb[style->font_family]) ofont = ofb[style->font_family];
|
if(ofb[fstyle->family]) ofont = ofb[fstyle->family];
|
||||||
else ofont = of[style->font_family];
|
else ofont = of[fstyle->family];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NSA_BOLDITALIC:
|
case NSA_BOLDITALIC:
|
||||||
if(ofbi[style->font_family]) ofont = ofbi[style->font_family];
|
if(ofbi[fstyle->family]) ofont = ofbi[fstyle->family];
|
||||||
else ofont = of[style->font_family];
|
else ofont = of[fstyle->family];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
ofont = of[style->font_family];
|
ofont = of[fstyle->family];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
ysize = css_len2pt(&style->font_size.value.length, style);
|
ysize = fstyle->size;
|
||||||
|
|
||||||
if(ysize < (option_font_min_size / 10))
|
if(ysize < (option_font_min_size / 10))
|
||||||
ysize = option_font_min_size / 10;
|
ysize = option_font_min_size / 10;
|
||||||
@ -296,7 +284,7 @@ struct OutlineFont *ami_open_outline_font(const struct css_style *style)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ULONG ami_unicode_text(struct RastPort *rp,const char *string,ULONG length,const struct css_style *style,ULONG dx, ULONG dy, ULONG c)
|
ULONG ami_unicode_text(struct RastPort *rp,const char *string,ULONG length,const plot_font_style_t *fstyle,ULONG dx, ULONG dy)
|
||||||
{
|
{
|
||||||
uint16 *utf16 = NULL, *outf16 = NULL;
|
uint16 *utf16 = NULL, *outf16 = NULL;
|
||||||
struct OutlineFont *ofont;
|
struct OutlineFont *ofont;
|
||||||
@ -317,9 +305,9 @@ ULONG ami_unicode_text(struct RastPort *rp,const char *string,ULONG length,const
|
|||||||
len = utf8_bounded_length(string, length);
|
len = utf8_bounded_length(string, length);
|
||||||
if(utf8_to_enc(string,"UTF-16",length,(char **)&utf16) != UTF8_CONVERT_OK) return 0;
|
if(utf8_to_enc(string,"UTF-16",length,(char **)&utf16) != UTF8_CONVERT_OK) return 0;
|
||||||
outf16 = utf16;
|
outf16 = utf16;
|
||||||
if(!(ofont = ami_open_outline_font(style))) return 0;
|
if(!(ofont = ami_open_outline_font(fstyle))) return 0;
|
||||||
|
|
||||||
if(rp) SetRPAttrs(rp,RPTAG_APenColor,p96EncodeColor(RGBFB_A8B8G8R8,c),TAG_DONE);
|
if(rp) SetRPAttrs(rp,RPTAG_APenColor,p96EncodeColor(RGBFB_A8B8G8R8,fstyle->foreground),TAG_DONE);
|
||||||
|
|
||||||
dy++;
|
dy++;
|
||||||
|
|
||||||
@ -377,19 +365,19 @@ void ami_init_fonts(void)
|
|||||||
|
|
||||||
switch(option_font_default)
|
switch(option_font_default)
|
||||||
{
|
{
|
||||||
case CSS_FONT_FAMILY_SANS_SERIF:
|
case PLOT_FONT_FAMILY_SANS_SERIF:
|
||||||
deffont = strdup(option_font_sans);
|
deffont = strdup(option_font_sans);
|
||||||
break;
|
break;
|
||||||
case CSS_FONT_FAMILY_SERIF:
|
case PLOT_FONT_FAMILY_SERIF:
|
||||||
deffont = strdup(option_font_serif);
|
deffont = strdup(option_font_serif);
|
||||||
break;
|
break;
|
||||||
case CSS_FONT_FAMILY_MONOSPACE:
|
case PLOT_FONT_FAMILY_MONOSPACE:
|
||||||
deffont = strdup(option_font_mono);
|
deffont = strdup(option_font_mono);
|
||||||
break;
|
break;
|
||||||
case CSS_FONT_FAMILY_CURSIVE:
|
case PLOT_FONT_FAMILY_CURSIVE:
|
||||||
deffont = strdup(option_font_cursive);
|
deffont = strdup(option_font_cursive);
|
||||||
break;
|
break;
|
||||||
case CSS_FONT_FAMILY_FANTASY:
|
case PLOT_FONT_FAMILY_FANTASY:
|
||||||
deffont = strdup(option_font_fantasy);
|
deffont = strdup(option_font_fantasy);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -397,15 +385,13 @@ void ami_init_fonts(void)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
of[CSS_FONT_FAMILY_SANS_SERIF] = OpenOutlineFont(option_font_sans,NULL,OFF_OPEN);
|
of[PLOT_FONT_FAMILY_SANS_SERIF] = OpenOutlineFont(option_font_sans,NULL,OFF_OPEN);
|
||||||
of[CSS_FONT_FAMILY_SERIF] = OpenOutlineFont(option_font_serif,NULL,OFF_OPEN);
|
of[PLOT_FONT_FAMILY_SERIF] = OpenOutlineFont(option_font_serif,NULL,OFF_OPEN);
|
||||||
of[CSS_FONT_FAMILY_MONOSPACE] = OpenOutlineFont(option_font_mono,NULL,OFF_OPEN);
|
of[PLOT_FONT_FAMILY_MONOSPACE] = OpenOutlineFont(option_font_mono,NULL,OFF_OPEN);
|
||||||
of[CSS_FONT_FAMILY_CURSIVE] = OpenOutlineFont(option_font_cursive,NULL,OFF_OPEN);
|
of[PLOT_FONT_FAMILY_CURSIVE] = OpenOutlineFont(option_font_cursive,NULL,OFF_OPEN);
|
||||||
of[CSS_FONT_FAMILY_FANTASY] = OpenOutlineFont(option_font_fantasy,NULL,OFF_OPEN);
|
of[PLOT_FONT_FAMILY_FANTASY] = OpenOutlineFont(option_font_fantasy,NULL,OFF_OPEN);
|
||||||
of[CSS_FONT_FAMILY_UNKNOWN] = OpenOutlineFont(deffont,NULL,OFF_OPEN);
|
|
||||||
of[CSS_FONT_FAMILY_NOT_SET] = OpenOutlineFont(deffont,NULL,OFF_OPEN);
|
|
||||||
|
|
||||||
for(i=CSS_FONT_FAMILY_SANS_SERIF;i<=CSS_FONT_FAMILY_NOT_SET;i++)
|
for(i=PLOT_FONT_FAMILY_SANS_SERIF;i<=PLOT_FONT_FAMILY_FANTASY;i++)
|
||||||
{
|
{
|
||||||
if(!of[i]) warn_user("FontError",""); // temporary error message
|
if(!of[i]) warn_user("FontError",""); // temporary error message
|
||||||
|
|
||||||
@ -443,7 +429,7 @@ void ami_close_fonts(void)
|
|||||||
{
|
{
|
||||||
int i=0;
|
int i=0;
|
||||||
|
|
||||||
for(i=CSS_FONT_FAMILY_SANS_SERIF;i<=CSS_FONT_FAMILY_NOT_SET;i++)
|
for(i=PLOT_FONT_FAMILY_SANS_SERIF;i<=PLOT_FONT_FAMILY_FANTASY;i++)
|
||||||
{
|
{
|
||||||
if(of[i]) CloseOutlineFont(of[i],NULL);
|
if(of[i]) CloseOutlineFont(of[i],NULL);
|
||||||
if(ofb[i]) CloseOutlineFont(ofb[i],NULL);
|
if(ofb[i]) CloseOutlineFont(ofb[i],NULL);
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
#ifndef AMIGA_FONT_H
|
#ifndef AMIGA_FONT_H
|
||||||
#define AMIGA_FONT_H
|
#define AMIGA_FONT_H
|
||||||
|
|
||||||
#include "css/css.h"
|
#include "desktop/plotters.h"
|
||||||
#include <graphics/text.h>
|
#include <graphics/text.h>
|
||||||
|
|
||||||
#define NSA_NORMAL 0
|
#define NSA_NORMAL 0
|
||||||
@ -27,9 +27,8 @@
|
|||||||
#define NSA_BOLD 2
|
#define NSA_BOLD 2
|
||||||
#define NSA_BOLDITALIC 3
|
#define NSA_BOLDITALIC 3
|
||||||
|
|
||||||
struct TextFont *ami_open_font(struct css_style *);
|
|
||||||
void ami_close_font(struct TextFont *tfont);
|
void ami_close_font(struct TextFont *tfont);
|
||||||
ULONG ami_unicode_text(struct RastPort *rp,const char *string,ULONG length,const struct css_style *style,ULONG x,ULONG y,ULONG c);
|
ULONG ami_unicode_text(struct RastPort *rp,const char *string,ULONG length,const plot_font_style_t *fstyle,ULONG x,ULONG y);
|
||||||
|
|
||||||
void ami_init_fonts(void);
|
void ami_init_fonts(void);
|
||||||
void ami_close_fonts(void);
|
void ami_close_fonts(void);
|
||||||
|
@ -791,7 +791,7 @@ void ami_gui_opts_open(void)
|
|||||||
GA_RelVerify, TRUE,
|
GA_RelVerify, TRUE,
|
||||||
CHOOSER_PopUp, TRUE,
|
CHOOSER_PopUp, TRUE,
|
||||||
CHOOSER_LabelArray, fontopts,
|
CHOOSER_LabelArray, fontopts,
|
||||||
CHOOSER_Selected, option_font_default - CSS_FONT_FAMILY_SANS_SERIF,
|
CHOOSER_Selected, option_font_default - PLOT_FONT_FAMILY_SANS_SERIF,
|
||||||
ChooserEnd,
|
ChooserEnd,
|
||||||
CHILD_Label, LabelObject,
|
CHILD_Label, LabelObject,
|
||||||
LABEL_Text, gadlab[GID_OPTS_FONT_DEFAULT],
|
LABEL_Text, gadlab[GID_OPTS_FONT_DEFAULT],
|
||||||
@ -1301,7 +1301,7 @@ void ami_gui_opts_use(void)
|
|||||||
option_font_fantasy = (char *)strdup((char *)tattr->ta_Name);
|
option_font_fantasy = (char *)strdup((char *)tattr->ta_Name);
|
||||||
|
|
||||||
GetAttr(CHOOSER_Selected,gow->gadgets[GID_OPTS_FONT_DEFAULT],(ULONG *)&option_font_default);
|
GetAttr(CHOOSER_Selected,gow->gadgets[GID_OPTS_FONT_DEFAULT],(ULONG *)&option_font_default);
|
||||||
option_font_default += CSS_FONT_FAMILY_SANS_SERIF;
|
option_font_default += PLOT_FONT_FAMILY_SANS_SERIF;
|
||||||
|
|
||||||
GetAttr(INTEGER_Number,gow->gadgets[GID_OPTS_FONT_SIZE],(ULONG *)&option_font_size);
|
GetAttr(INTEGER_Number,gow->gadgets[GID_OPTS_FONT_SIZE],(ULONG *)&option_font_size);
|
||||||
option_font_size *= 10;
|
option_font_size *= 10;
|
||||||
|
@ -400,10 +400,10 @@ bool ami_clip(int x0, int y0, int x1, int y1)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ami_text(int x, int y, const struct css_style *style,
|
bool ami_text(int x, int y, const char *text, size_t length,
|
||||||
const char *text, size_t length, colour bg, colour c)
|
const plot_font_style_t *fstyle)
|
||||||
{
|
{
|
||||||
ami_unicode_text(&glob->rp,text,length,style,x,y,c);
|
ami_unicode_text(&glob->rp,text,length,fstyle,x,y);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,8 +46,8 @@ bool ami_rectangle(int x0, int y0, int x1, int y1, const plot_style_t *style);
|
|||||||
bool ami_line(int x0, int y0, int x1, int y1, const plot_style_t *style);
|
bool ami_line(int x0, int y0, int x1, int y1, const plot_style_t *style);
|
||||||
bool ami_polygon(const int *p, unsigned int n, const plot_style_t *style);
|
bool ami_polygon(const int *p, unsigned int n, const plot_style_t *style);
|
||||||
bool ami_clip(int x0, int y0, int x1, int y1);
|
bool ami_clip(int x0, int y0, int x1, int y1);
|
||||||
bool ami_text(int x, int y, const struct css_style *style,
|
bool ami_text(int x, int y, const char *text, size_t length,
|
||||||
const char *text, size_t length, colour bg, colour c);
|
const plot_font_style_t *fstyle);
|
||||||
bool ami_disc(int x, int y, int radius, const plot_style_t *style);
|
bool ami_disc(int x, int y, int radius, const plot_style_t *style);
|
||||||
bool ami_arc(int x, int y, int radius, int angle1, int angle2,
|
bool ami_arc(int x, int y, int radius, int angle1, int angle2,
|
||||||
const plot_style_t *style);
|
const plot_style_t *style);
|
||||||
|
@ -42,13 +42,13 @@ extern "C" {
|
|||||||
#include "beos/beos_font.h"
|
#include "beos/beos_font.h"
|
||||||
#include "beos/beos_plotters.h"
|
#include "beos/beos_plotters.h"
|
||||||
|
|
||||||
static bool nsfont_width(const struct css_style *style,
|
static bool nsfont_width(const plot_font_style_t *fstyle,
|
||||||
const char *string, size_t length,
|
const char *string, size_t length,
|
||||||
int *width);
|
int *width);
|
||||||
static bool nsfont_position_in_string(const struct css_style *style,
|
static bool nsfont_position_in_string(const plot_font_style_t *fstyle,
|
||||||
const char *string, size_t length,
|
const char *string, size_t length,
|
||||||
int x, size_t *char_offset, int *actual_x);
|
int x, size_t *char_offset, int *actual_x);
|
||||||
static bool nsfont_split(const struct css_style *style,
|
static bool nsfont_split(const plot_font_style_t *fstyle,
|
||||||
const char *string, size_t length,
|
const char *string, size_t length,
|
||||||
int x, size_t *char_offset, int *actual_x);
|
int x, size_t *char_offset, int *actual_x);
|
||||||
|
|
||||||
@ -62,15 +62,14 @@ const struct font_functions nsfont = {
|
|||||||
/**
|
/**
|
||||||
* Measure the width of a string.
|
* Measure the width of a string.
|
||||||
*
|
*
|
||||||
* \param style css_style for this text, with style->font_size.size ==
|
* \param fstyle style for this text
|
||||||
* CSS_FONT_SIZE_LENGTH
|
|
||||||
* \param string UTF-8 string to measure
|
* \param string UTF-8 string to measure
|
||||||
* \param length length of string
|
* \param length length of string
|
||||||
* \param width updated to width of string[0..length)
|
* \param width updated to width of string[0..length)
|
||||||
* \return true on success, false on error and error reported
|
* \return true on success, false on error and error reported
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool nsfont_width(const struct css_style *style,
|
bool nsfont_width(const plot_font_style_t *fstyle,
|
||||||
const char *string, size_t length,
|
const char *string, size_t length,
|
||||||
int *width)
|
int *width)
|
||||||
{
|
{
|
||||||
@ -82,7 +81,7 @@ bool nsfont_width(const struct css_style *style,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsbeos_style_to_font(font, style);
|
nsbeos_style_to_font(font, fstyle);
|
||||||
*width = (int)font.StringWidth(string, length);
|
*width = (int)font.StringWidth(string, length);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -113,8 +112,7 @@ static int utf8_char_len(const char *c)
|
|||||||
/**
|
/**
|
||||||
* Find the position in a string where an x coordinate falls.
|
* Find the position in a string where an x coordinate falls.
|
||||||
*
|
*
|
||||||
* \param style css_style for this text, with style->font_size.size ==
|
* \param fstyle style for this text
|
||||||
* CSS_FONT_SIZE_LENGTH
|
|
||||||
* \param string UTF-8 string to measure
|
* \param string UTF-8 string to measure
|
||||||
* \param length length of string
|
* \param length length of string
|
||||||
* \param x x coordinate to search for
|
* \param x x coordinate to search for
|
||||||
@ -123,7 +121,7 @@ static int utf8_char_len(const char *c)
|
|||||||
* \return true on success, false on error and error reported
|
* \return true on success, false on error and error reported
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool nsfont_position_in_string(const struct css_style *style,
|
bool nsfont_position_in_string(const plot_font_style_t *fstyle,
|
||||||
const char *string, size_t length,
|
const char *string, size_t length,
|
||||||
int x, size_t *char_offset, int *actual_x)
|
int x, size_t *char_offset, int *actual_x)
|
||||||
{
|
{
|
||||||
@ -132,7 +130,7 @@ bool nsfont_position_in_string(const struct css_style *style,
|
|||||||
int index;
|
int index;
|
||||||
BFont font;
|
BFont font;
|
||||||
|
|
||||||
nsbeos_style_to_font(font, style);
|
nsbeos_style_to_font(font, fstyle);
|
||||||
BString str(string);
|
BString str(string);
|
||||||
int32 len = str.CountChars();
|
int32 len = str.CountChars();
|
||||||
float escapements[len];
|
float escapements[len];
|
||||||
@ -159,8 +157,7 @@ bool nsfont_position_in_string(const struct css_style *style,
|
|||||||
/**
|
/**
|
||||||
* Find where to split a string to make it fit a width.
|
* Find where to split a string to make it fit a width.
|
||||||
*
|
*
|
||||||
* \param style css_style for this text, with style->font_size.size ==
|
* \param fstyle style for this text
|
||||||
* CSS_FONT_SIZE_LENGTH
|
|
||||||
* \param string UTF-8 string to measure
|
* \param string UTF-8 string to measure
|
||||||
* \param length length of string
|
* \param length length of string
|
||||||
* \param x width available
|
* \param x width available
|
||||||
@ -173,7 +170,7 @@ bool nsfont_position_in_string(const struct css_style *style,
|
|||||||
* char_offset == length]
|
* char_offset == length]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool nsfont_split(const struct css_style *style,
|
bool nsfont_split(const plot_font_style_t *fstyle,
|
||||||
const char *string, size_t length,
|
const char *string, size_t length,
|
||||||
int x, size_t *char_offset, int *actual_x)
|
int x, size_t *char_offset, int *actual_x)
|
||||||
{
|
{
|
||||||
@ -182,7 +179,7 @@ bool nsfont_split(const struct css_style *style,
|
|||||||
int index = 0;
|
int index = 0;
|
||||||
BFont font;
|
BFont font;
|
||||||
|
|
||||||
nsbeos_style_to_font(font, style);
|
nsbeos_style_to_font(font, fstyle);
|
||||||
BString str(string);
|
BString str(string);
|
||||||
int32 len = str.CountChars();
|
int32 len = str.CountChars();
|
||||||
float escapements[len];
|
float escapements[len];
|
||||||
@ -217,8 +214,7 @@ bool nsfont_split(const struct css_style *style,
|
|||||||
/**
|
/**
|
||||||
* Render a string.
|
* Render a string.
|
||||||
*
|
*
|
||||||
* \param style css_style for this text, with style->font_size.size ==
|
* \param fstyle style for this text
|
||||||
* CSS_FONT_SIZE_LENGTH
|
|
||||||
* \param string UTF-8 string to measure
|
* \param string UTF-8 string to measure
|
||||||
* \param length length of string
|
* \param length length of string
|
||||||
* \param x x coordinate
|
* \param x x coordinate
|
||||||
@ -227,7 +223,7 @@ bool nsfont_split(const struct css_style *style,
|
|||||||
* \return true on success, false on error and error reported
|
* \return true on success, false on error and error reported
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool nsfont_paint(const struct css_style *style,
|
bool nsfont_paint(const plot_font_style_t *fstyle,
|
||||||
const char *string, size_t length,
|
const char *string, size_t length,
|
||||||
int x, int y, colour bg, colour c)
|
int x, int y, colour bg, colour c)
|
||||||
{
|
{
|
||||||
@ -243,7 +239,7 @@ bool nsfont_paint(const struct css_style *style,
|
|||||||
if (length == 0)
|
if (length == 0)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
nsbeos_style_to_font(font, style);
|
nsbeos_style_to_font(font, fstyle);
|
||||||
background = nsbeos_rgb_colour(bg);
|
background = nsbeos_rgb_colour(bg);
|
||||||
foreground = nsbeos_rgb_colour(c);
|
foreground = nsbeos_rgb_colour(c);
|
||||||
|
|
||||||
@ -287,77 +283,59 @@ bool nsfont_paint(const struct css_style *style,
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a css_style to a PangoFontDescription.
|
* Convert a font style to a PangoFontDescription.
|
||||||
*
|
*
|
||||||
* \param style css_style for this text, with style->font_size.size ==
|
* \param fstyle style for this text
|
||||||
* CSS_FONT_SIZE_LENGTH
|
|
||||||
* \return a new Pango font description
|
* \return a new Pango font description
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void nsbeos_style_to_font(BFont &font,
|
void nsbeos_style_to_font(BFont &font, const plot_font_style_t *style)
|
||||||
const struct css_style *style)
|
|
||||||
{
|
{
|
||||||
float size;
|
float size;
|
||||||
uint16 face = 0;
|
uint16 face = 0;
|
||||||
const char *family;
|
const char *family;
|
||||||
|
|
||||||
assert(style->font_size.size == CSS_FONT_SIZE_LENGTH);
|
switch (fstyle->family) {
|
||||||
|
case PLOT_FONT_FAMILY_SERIF:
|
||||||
switch (style->font_family) {
|
|
||||||
case CSS_FONT_FAMILY_SERIF:
|
|
||||||
family = option_font_serif;
|
family = option_font_serif;
|
||||||
break;
|
break;
|
||||||
case CSS_FONT_FAMILY_MONOSPACE:
|
case PLOT_FONT_FAMILY_MONOSPACE:
|
||||||
family = option_font_mono;
|
family = option_font_mono;
|
||||||
break;
|
break;
|
||||||
case CSS_FONT_FAMILY_CURSIVE:
|
case PLOT_FONT_FAMILY_CURSIVE:
|
||||||
family = option_font_cursive;
|
family = option_font_cursive;
|
||||||
break;
|
break;
|
||||||
case CSS_FONT_FAMILY_FANTASY:
|
case PLOT_FONT_FAMILY_FANTASY:
|
||||||
family = option_font_fantasy;
|
family = option_font_fantasy;
|
||||||
break;
|
break;
|
||||||
case CSS_FONT_FAMILY_SANS_SERIF:
|
case PLOT_FONT_FAMILY_SANS_SERIF:
|
||||||
default:
|
default:
|
||||||
family = option_font_sans;
|
family = option_font_sans;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((fstyle->flags & FONTF_ITALIC)) {
|
||||||
switch (style->font_style) {
|
|
||||||
case CSS_FONT_STYLE_ITALIC:
|
|
||||||
face = B_ITALIC_FACE;
|
face = B_ITALIC_FACE;
|
||||||
break;
|
} else if ((fstyle->flags & FONTF_OBLIQUE)) {
|
||||||
case CSS_FONT_STYLE_OBLIQUE:
|
|
||||||
face = B_ITALIC_FACE;
|
face = B_ITALIC_FACE;
|
||||||
// XXX: no OBLIQUE flag ??
|
// XXX: no OBLIQUE flag ??
|
||||||
// maybe find "Oblique" style
|
// maybe find "Oblique" style
|
||||||
// or use SetShear() ?
|
// or use SetShear() ?
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (style->font_weight) {
|
|
||||||
case CSS_FONT_WEIGHT_NORMAL:
|
|
||||||
break;
|
|
||||||
case CSS_FONT_WEIGHT_BOLD:
|
|
||||||
case CSS_FONT_WEIGHT_600:
|
|
||||||
case CSS_FONT_WEIGHT_700:
|
|
||||||
#ifndef __HAIKU__XXX
|
#ifndef __HAIKU__XXX
|
||||||
case CSS_FONT_WEIGHT_800:
|
if (fstyle->weight >= 600) {
|
||||||
case CSS_FONT_WEIGHT_900:
|
face |= B_BOLD_FACE;
|
||||||
#endif
|
}
|
||||||
face |= B_BOLD_FACE; break;
|
#else
|
||||||
#ifdef __HAIKU__XXX
|
if (fstyle->weight >= 600) {
|
||||||
case CSS_FONT_WEIGHT_BOLDER:
|
if (fstyle->weight >= 800)
|
||||||
case CSS_FONT_WEIGHT_800:
|
face |= B_HEAVY_FACE;
|
||||||
case CSS_FONT_WEIGHT_900:
|
else
|
||||||
face |= B_HEAVY_FACE; break;
|
face |= B_BOLD_FACE;
|
||||||
case CSS_FONT_WEIGHT_100:
|
} else if (fstyle->weight <= 300) {
|
||||||
case CSS_FONT_WEIGHT_200:
|
face |= B_LIGHT_FACE;
|
||||||
case CSS_FONT_WEIGHT_300:
|
}
|
||||||
case CSS_FONT_WEIGHT_LIGHTER:
|
|
||||||
face |= B_LIGHT_FACE; break;
|
|
||||||
#endif
|
#endif
|
||||||
/*
|
/*
|
||||||
case CSS_FONT_WEIGHT_100: weight = 100; break;
|
case CSS_FONT_WEIGHT_100: weight = 100; break;
|
||||||
@ -387,11 +365,7 @@ void nsbeos_style_to_font(BFont &font,
|
|||||||
}
|
}
|
||||||
|
|
||||||
//fprintf(stderr, "nsbeos_style_to_font: value %f unit %d\n", style->font_size.value.length.value, style->font_size.value.length.unit);
|
//fprintf(stderr, "nsbeos_style_to_font: value %f unit %d\n", style->font_size.value.length.value, style->font_size.value.length.unit);
|
||||||
if (style->font_size.value.length.unit == CSS_UNIT_PT)
|
size = fstyle->size;
|
||||||
size = style->font_size.value.length.value;
|
|
||||||
else
|
|
||||||
size = css_len2pt(&style->font_size.value.length, style);
|
|
||||||
// * 72.0 / 90.0;
|
|
||||||
|
|
||||||
//XXX: pango stuff ?
|
//XXX: pango stuff ?
|
||||||
if (size < abs(option_font_min_size / 10))
|
if (size < abs(option_font_min_size / 10))
|
||||||
|
@ -22,12 +22,10 @@
|
|||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#include "desktop/plotters.h"
|
||||||
|
|
||||||
struct css_style;
|
bool nsfont_paint(const plot_font_style_t *fstyle,
|
||||||
|
|
||||||
bool nsfont_paint(const struct css_style *style,
|
|
||||||
const char *string, size_t length,
|
const char *string, size_t length,
|
||||||
int x, int y, colour bg, colour c);
|
int x, int y);
|
||||||
|
|
||||||
void nsbeos_style_to_font(BFont &font,
|
void nsbeos_style_to_font(BFont &font, const plot_font_style_t *fstyle);
|
||||||
const struct css_style *style);
|
|
||||||
|
@ -68,8 +68,8 @@ static bool nsbeos_plot_path(const float *p, unsigned int n, colour fill, float
|
|||||||
colour c, const float transform[6]);
|
colour c, const float transform[6]);
|
||||||
static bool nsbeos_plot_clip(int clip_x0, int clip_y0,
|
static bool nsbeos_plot_clip(int clip_x0, int clip_y0,
|
||||||
int clip_x1, int clip_y1);
|
int clip_x1, int clip_y1);
|
||||||
static bool nsbeos_plot_text(int x, int y, const struct css_style *style,
|
static bool nsbeos_plot_text(int x, int y, const char *text, size_t length,
|
||||||
const char *text, size_t length, colour bg, colour c);
|
const plot_font_style_t *fstyle);
|
||||||
static bool nsbeos_plot_disc(int x, int y, int radius, const plot_style_t *style);
|
static bool nsbeos_plot_disc(int x, int y, int radius, const plot_style_t *style);
|
||||||
static bool nsbeos_plot_arc(int x, int y, int radius, int angle1, int angle2,
|
static bool nsbeos_plot_arc(int x, int y, int radius, int angle1, int angle2,
|
||||||
const plot_style_t *style);
|
const plot_style_t *style);
|
||||||
@ -394,10 +394,10 @@ bool nsbeos_plot_clip(int clip_x0, int clip_y0,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool nsbeos_plot_text(int x, int y, const struct css_style *style,
|
bool nsbeos_plot_text(int x, int y, const char *text, size_t length,
|
||||||
const char *text, size_t length, colour bg, colour c)
|
const plot_font_style_t *fstyle)
|
||||||
{
|
{
|
||||||
return nsfont_paint(style, text, length, x, y, bg, c);
|
return nsfont_paint(fstyle, text, length, x, y, bg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1405,6 +1405,7 @@ void browser_window_mouse_action_html(struct browser_window *bw,
|
|||||||
struct form_control *gadget = 0;
|
struct form_control *gadget = 0;
|
||||||
struct content *object = NULL;
|
struct content *object = NULL;
|
||||||
struct box *next_box;
|
struct box *next_box;
|
||||||
|
plot_font_style_t fstyle;
|
||||||
|
|
||||||
bw->drag_type = DRAGGING_NONE;
|
bw->drag_type = DRAGGING_NONE;
|
||||||
bw->scrolling_box = NULL;
|
bw->scrolling_box = NULL;
|
||||||
@ -1554,7 +1555,10 @@ void browser_window_mouse_action_html(struct browser_window *bw,
|
|||||||
int pixel_offset;
|
int pixel_offset;
|
||||||
size_t idx;
|
size_t idx;
|
||||||
|
|
||||||
nsfont.font_position_in_string(text_box->style,
|
font_plot_style_from_css(text_box->style,
|
||||||
|
&fstyle);
|
||||||
|
|
||||||
|
nsfont.font_position_in_string(&fstyle,
|
||||||
text_box->text,
|
text_box->text,
|
||||||
text_box->length,
|
text_box->length,
|
||||||
x - gadget_box_x - text_box->x,
|
x - gadget_box_x - text_box->x,
|
||||||
@ -1596,7 +1600,10 @@ void browser_window_mouse_action_html(struct browser_window *bw,
|
|||||||
BROWSER_MOUSE_DRAG_2))
|
BROWSER_MOUSE_DRAG_2))
|
||||||
selection_init(bw->sel, gadget_box);
|
selection_init(bw->sel, gadget_box);
|
||||||
|
|
||||||
nsfont.font_position_in_string(text_box->style,
|
font_plot_style_from_css(text_box->style,
|
||||||
|
&fstyle);
|
||||||
|
|
||||||
|
nsfont.font_position_in_string(&fstyle,
|
||||||
text_box->text,
|
text_box->text,
|
||||||
text_box->length,
|
text_box->length,
|
||||||
x - gadget_box_x - text_box->x,
|
x - gadget_box_x - text_box->x,
|
||||||
@ -1694,7 +1701,10 @@ void browser_window_mouse_action_html(struct browser_window *bw,
|
|||||||
int pixel_offset;
|
int pixel_offset;
|
||||||
size_t idx;
|
size_t idx;
|
||||||
|
|
||||||
nsfont.font_position_in_string(text_box->style,
|
font_plot_style_from_css(text_box->style,
|
||||||
|
&fstyle);
|
||||||
|
|
||||||
|
nsfont.font_position_in_string(&fstyle,
|
||||||
text_box->text,
|
text_box->text,
|
||||||
text_box->length,
|
text_box->length,
|
||||||
x - text_box_x,
|
x - text_box_x,
|
||||||
@ -1972,7 +1982,11 @@ void browser_window_mouse_track_html(struct browser_window *bw,
|
|||||||
if (box) {
|
if (box) {
|
||||||
int pixel_offset;
|
int pixel_offset;
|
||||||
size_t idx;
|
size_t idx;
|
||||||
nsfont.font_position_in_string(box->style,
|
plot_font_style_t fstyle;
|
||||||
|
|
||||||
|
font_plot_style_from_css(box->style, &fstyle);
|
||||||
|
|
||||||
|
nsfont.font_position_in_string(&fstyle,
|
||||||
box->text, box->length,
|
box->text, box->length,
|
||||||
dx, &idx, &pixel_offset);
|
dx, &idx, &pixel_offset);
|
||||||
|
|
||||||
@ -2052,8 +2066,14 @@ void browser_window_mouse_drag_end(struct browser_window *bw,
|
|||||||
box = browser_window_pick_text_box(bw,
|
box = browser_window_pick_text_box(bw,
|
||||||
x, y, dir, &dx, &dy);
|
x, y, dir, &dx, &dy);
|
||||||
if (box) {
|
if (box) {
|
||||||
|
plot_font_style_t fstyle;
|
||||||
|
|
||||||
|
font_plot_style_from_css(
|
||||||
|
box->style,
|
||||||
|
&fstyle);
|
||||||
|
|
||||||
nsfont.font_position_in_string(
|
nsfont.font_position_in_string(
|
||||||
box->style,
|
&fstyle,
|
||||||
box->text,
|
box->text,
|
||||||
box->length,
|
box->length,
|
||||||
dx,
|
dx,
|
||||||
|
@ -633,6 +633,7 @@ bool history_redraw_entry(struct history *history,
|
|||||||
.stroke_colour = c,
|
.stroke_colour = c,
|
||||||
.stroke_width = entry == history->current ? 2 : 1,
|
.stroke_width = entry == history->current ? 2 : 1,
|
||||||
};
|
};
|
||||||
|
plot_font_style_t fstyle = *plot_style_font;
|
||||||
|
|
||||||
if (clip) {
|
if (clip) {
|
||||||
if(!plot.clip(x0 + xoffset, y0 + yoffset, x1 + xoffset, y1 + yoffset))
|
if(!plot.clip(x0 + xoffset, y0 + yoffset, x1 + xoffset, y1 + yoffset))
|
||||||
@ -649,12 +650,16 @@ bool history_redraw_entry(struct history *history,
|
|||||||
&pstyle_history_rect))
|
&pstyle_history_rect))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!nsfont.font_position_in_string(&css_base_style, entry->page.title,
|
if (!nsfont.font_position_in_string(plot_style_font, entry->page.title,
|
||||||
strlen(entry->page.title), WIDTH,
|
strlen(entry->page.title), WIDTH,
|
||||||
&char_offset, &actual_x))
|
&char_offset, &actual_x))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
fstyle.background = 0xffffff;
|
||||||
|
fstyle.foreground = c;
|
||||||
|
|
||||||
if (!plot.text(entry->x + xoffset, entry->y + HEIGHT + 12 + yoffset,
|
if (!plot.text(entry->x + xoffset, entry->y + HEIGHT + 12 + yoffset,
|
||||||
&css_base_style, entry->page.title, char_offset, 0xffffff, c))
|
entry->page.title, char_offset, &fstyle))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
for (child = entry->forward; child; child = child->next) {
|
for (child = entry->forward; child; child = child->next) {
|
||||||
|
@ -90,8 +90,8 @@ static bool knockout_plot_polygon(const int *p, unsigned int n, const plot_style
|
|||||||
static bool knockout_plot_rectangle(int x0, int y0, int x1, int y1, const plot_style_t *plot_style);
|
static bool knockout_plot_rectangle(int x0, int y0, int x1, int y1, const plot_style_t *plot_style);
|
||||||
static bool knockout_plot_clip(int clip_x0, int clip_y0,
|
static bool knockout_plot_clip(int clip_x0, int clip_y0,
|
||||||
int clip_x1, int clip_y1);
|
int clip_x1, int clip_y1);
|
||||||
static bool knockout_plot_text(int x, int y, const struct css_style *style,
|
static bool knockout_plot_text(int x, int y, const char *text, size_t length,
|
||||||
const char *text, size_t length, colour bg, colour c);
|
const plot_font_style_t *fstyle);
|
||||||
static bool knockout_plot_disc(int x, int y, int radius, const plot_style_t *pstyle);
|
static bool knockout_plot_disc(int x, int y, int radius, const plot_style_t *pstyle);
|
||||||
static bool knockout_plot_arc(int x, int y, int radius, int angle1, int angle2, const plot_style_t *pstyle);
|
static bool knockout_plot_arc(int x, int y, int radius, int angle1, int angle2, const plot_style_t *pstyle);
|
||||||
static bool knockout_plot_bitmap(int x, int y, int width, int height,
|
static bool knockout_plot_bitmap(int x, int y, int width, int height,
|
||||||
@ -188,11 +188,9 @@ struct knockout_entry {
|
|||||||
struct {
|
struct {
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
const struct css_style *style;
|
|
||||||
const char *text;
|
const char *text;
|
||||||
size_t length;
|
size_t length;
|
||||||
colour bg;
|
plot_font_style_t font_style;
|
||||||
colour c;
|
|
||||||
} text;
|
} text;
|
||||||
struct {
|
struct {
|
||||||
int x;
|
int x;
|
||||||
@ -350,11 +348,9 @@ bool knockout_plot_flush(void)
|
|||||||
success &= plot.text(
|
success &= plot.text(
|
||||||
knockout_entries[i].data.text.x,
|
knockout_entries[i].data.text.x,
|
||||||
knockout_entries[i].data.text.y,
|
knockout_entries[i].data.text.y,
|
||||||
knockout_entries[i].data.text.style,
|
|
||||||
knockout_entries[i].data.text.text,
|
knockout_entries[i].data.text.text,
|
||||||
knockout_entries[i].data.text.length,
|
knockout_entries[i].data.text.length,
|
||||||
knockout_entries[i].data.text.bg,
|
&knockout_entries[i].data.text.font_style);
|
||||||
knockout_entries[i].data.text.c);
|
|
||||||
break;
|
break;
|
||||||
case KNOCKOUT_PLOT_DISC:
|
case KNOCKOUT_PLOT_DISC:
|
||||||
success &= plot.disc(
|
success &= plot.disc(
|
||||||
@ -737,16 +733,14 @@ bool knockout_plot_clip(int clip_x0, int clip_y0,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool knockout_plot_text(int x, int y, const struct css_style *style,
|
bool knockout_plot_text(int x, int y, const char *text, size_t length,
|
||||||
const char *text, size_t length, colour bg, colour c)
|
const plot_font_style_t *fstyle)
|
||||||
{
|
{
|
||||||
knockout_entries[knockout_entry_cur].data.text.x = x;
|
knockout_entries[knockout_entry_cur].data.text.x = x;
|
||||||
knockout_entries[knockout_entry_cur].data.text.y = y;
|
knockout_entries[knockout_entry_cur].data.text.y = y;
|
||||||
knockout_entries[knockout_entry_cur].data.text.style = style;
|
|
||||||
knockout_entries[knockout_entry_cur].data.text.text = text;
|
knockout_entries[knockout_entry_cur].data.text.text = text;
|
||||||
knockout_entries[knockout_entry_cur].data.text.length = length;
|
knockout_entries[knockout_entry_cur].data.text.length = length;
|
||||||
knockout_entries[knockout_entry_cur].data.text.bg = bg;
|
knockout_entries[knockout_entry_cur].data.text.font_style = *fstyle;
|
||||||
knockout_entries[knockout_entry_cur].data.text.c = c;
|
|
||||||
knockout_entries[knockout_entry_cur].type = KNOCKOUT_PLOT_TEXT;
|
knockout_entries[knockout_entry_cur].type = KNOCKOUT_PLOT_TEXT;
|
||||||
if (++knockout_entry_cur >= KNOCKOUT_ENTRIES)
|
if (++knockout_entry_cur >= KNOCKOUT_ENTRIES)
|
||||||
knockout_plot_flush();
|
knockout_plot_flush();
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
#include "content/urldb.h"
|
#include "content/urldb.h"
|
||||||
#include "css/css.h"
|
#include "css/css.h"
|
||||||
#include "desktop/options.h"
|
#include "desktop/options.h"
|
||||||
|
#include "desktop/plot_style.h"
|
||||||
#include "desktop/tree.h"
|
#include "desktop/tree.h"
|
||||||
#include "utils/log.h"
|
#include "utils/log.h"
|
||||||
#include "utils/messages.h"
|
#include "utils/messages.h"
|
||||||
@ -103,7 +104,7 @@ bool option_animate_images = true;
|
|||||||
/** How many days to retain URL data for */
|
/** How many days to retain URL data for */
|
||||||
int option_expire_url = 28;
|
int option_expire_url = 28;
|
||||||
/** Default font family */
|
/** Default font family */
|
||||||
int option_font_default = CSS_FONT_FAMILY_SANS_SERIF;
|
int option_font_default = PLOT_FONT_FAMILY_SANS_SERIF;
|
||||||
/** ca-bundle location */
|
/** ca-bundle location */
|
||||||
char *option_ca_bundle = 0;
|
char *option_ca_bundle = 0;
|
||||||
/** ca-path location */
|
/** ca-path location */
|
||||||
|
@ -137,3 +137,14 @@ static plot_style_t plot_style_stroke_history_static = {
|
|||||||
};
|
};
|
||||||
plot_style_t *plot_style_stroke_history = &plot_style_stroke_history_static;
|
plot_style_t *plot_style_stroke_history = &plot_style_stroke_history_static;
|
||||||
|
|
||||||
|
/* Generic font style */
|
||||||
|
static const plot_font_style_t plot_style_font_static = {
|
||||||
|
.family = PLOT_FONT_FAMILY_SANS_SERIF,
|
||||||
|
.size = 10,
|
||||||
|
.weight = 400,
|
||||||
|
.flags = FONTF_NONE,
|
||||||
|
.background = 0xffffff,
|
||||||
|
.foreground = 0x000000,
|
||||||
|
};
|
||||||
|
plot_font_style_t const * const plot_style_font = &plot_style_font_static;
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/** \file
|
/** \file
|
||||||
* Ploter styles.
|
* Plotter styles.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _NETSURF_DESKTOP_PLOT_STYLE_H_
|
#ifndef _NETSURF_DESKTOP_PLOT_STYLE_H_
|
||||||
@ -27,27 +27,27 @@
|
|||||||
#define WIDGET_BASEC 0xd9d9d9
|
#define WIDGET_BASEC 0xd9d9d9
|
||||||
#define WIDGET_BLOBC 0x000000
|
#define WIDGET_BLOBC 0x000000
|
||||||
|
|
||||||
/* Darken a colour by taking three quaters of each channels intensity */
|
/* Darken a colour by taking three quarters of each channel's intensity */
|
||||||
#define darken_colour(c1) \
|
#define darken_colour(c1) \
|
||||||
((((3 * (c1 >> 16)) >> 2) << 16) | \
|
((((3 * (c1 >> 16)) >> 2) << 16) | \
|
||||||
(((3 * ((c1 >> 8) & 0xff)) >> 2) << 8) | \
|
(((3 * ((c1 >> 8) & 0xff)) >> 2) << 8) | \
|
||||||
(((3 * (c1 & 0xff)) >> 2) << 0))
|
(((3 * (c1 & 0xff)) >> 2) << 0))
|
||||||
|
|
||||||
/* Darken a colour by taking nine sixteenths of each channels intensity */
|
/* Darken a colour by taking nine sixteenths of each channel's intensity */
|
||||||
#define double_darken_colour(c1) \
|
#define double_darken_colour(c1) \
|
||||||
((((9 * (c1 >> 16)) >> 4) << 16) | \
|
((((9 * (c1 >> 16)) >> 4) << 16) | \
|
||||||
(((9 * ((c1 >> 8) & 0xff)) >> 4) << 8) | \
|
(((9 * ((c1 >> 8) & 0xff)) >> 4) << 8) | \
|
||||||
(((9 * (c1 & 0xff)) >> 4) << 0))
|
(((9 * (c1 & 0xff)) >> 4) << 0))
|
||||||
|
|
||||||
/* Lighten a colour by taking three quaters of each channels intensity
|
/* Lighten a colour by taking three quarters of each channel's intensity
|
||||||
* and adding a full quater
|
* and adding a full quarter
|
||||||
*/
|
*/
|
||||||
#define lighten_colour(c1) \
|
#define lighten_colour(c1) \
|
||||||
(((((3 * (c1 >> 16)) >> 2) + 64) << 16) | \
|
(((((3 * (c1 >> 16)) >> 2) + 64) << 16) | \
|
||||||
((((3 * ((c1 >> 8) & 0xff)) >> 2) + 64) << 8) | \
|
((((3 * ((c1 >> 8) & 0xff)) >> 2) + 64) << 8) | \
|
||||||
((((3 * (c1 & 0xff)) >> 2) + 64) << 0))
|
((((3 * (c1 & 0xff)) >> 2) + 64) << 0))
|
||||||
|
|
||||||
/* Lighten a colour by taking nine sixteenths of each channels intensity and
|
/* Lighten a colour by taking nine sixteenths of each channel's intensity and
|
||||||
* adding a full intensity 7/16ths */
|
* adding a full intensity 7/16ths */
|
||||||
#define double_lighten_colour(c1) \
|
#define double_lighten_colour(c1) \
|
||||||
(((((9 * (c1 >> 16)) >> 4) + 112) << 16) | \
|
(((((9 * (c1 >> 16)) >> 4) + 112) << 16) | \
|
||||||
@ -62,21 +62,60 @@
|
|||||||
(((((c0 >> 8) & 0xff) + ((c1 >> 8) & 0xff)) >> 1) << 8) | \
|
(((((c0 >> 8) & 0xff) + ((c1 >> 8) & 0xff)) >> 1) << 8) | \
|
||||||
((((c0 & 0xff) + (c1 & 0xff)) >> 1) << 0)
|
((((c0 & 0xff) + (c1 & 0xff)) >> 1) << 0)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Type of plot operation
|
||||||
|
*/
|
||||||
typedef enum {
|
typedef enum {
|
||||||
PLOT_OP_TYPE_NONE = 0, /**< No operation */
|
PLOT_OP_TYPE_NONE = 0, /**< No operation */
|
||||||
PLOT_OP_TYPE_SOLID, /**< Solid colour */
|
PLOT_OP_TYPE_SOLID, /**< Solid colour */
|
||||||
PLOT_OP_TYPE_DOT, /**< Doted plot */
|
PLOT_OP_TYPE_DOT, /**< Dotted plot */
|
||||||
PLOT_OP_TYPE_DASH, /**< dashed plot */
|
PLOT_OP_TYPE_DASH, /**< Dashed plot */
|
||||||
} plot_operation_type_t;
|
} plot_operation_type_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Plot style for stroke/fill plotters
|
||||||
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
plot_operation_type_t stroke_type;
|
plot_operation_type_t stroke_type; /**< Stroke plot type */
|
||||||
int stroke_width;
|
int stroke_width; /**< Width of stroke, in pixels */
|
||||||
colour stroke_colour;
|
colour stroke_colour; /**< Colour of stroke */
|
||||||
plot_operation_type_t fill_type;
|
plot_operation_type_t fill_type; /**< Fill plot type */
|
||||||
colour fill_colour;
|
colour fill_colour; /**< Colour of fill */
|
||||||
} plot_style_t;
|
} plot_style_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generic font family type
|
||||||
|
*/
|
||||||
|
typedef enum {
|
||||||
|
PLOT_FONT_FAMILY_SANS_SERIF = 0,
|
||||||
|
PLOT_FONT_FAMILY_SERIF,
|
||||||
|
PLOT_FONT_FAMILY_MONOSPACE,
|
||||||
|
PLOT_FONT_FAMILY_CURSIVE,
|
||||||
|
PLOT_FONT_FAMILY_FANTASY,
|
||||||
|
PLOT_FONT_FAMILY_COUNT /**< Number of generic families */
|
||||||
|
} plot_font_generic_family_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Font plot flags
|
||||||
|
*/
|
||||||
|
typedef unsigned long plot_font_flags_t;
|
||||||
|
#define FONTF_NONE 0
|
||||||
|
#define FONTF_ITALIC 1
|
||||||
|
#define FONTF_OBLIQUE 2
|
||||||
|
#define FONTF_SMALLCAPS 4
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Font style for plotting
|
||||||
|
*/
|
||||||
|
typedef struct {
|
||||||
|
plot_font_generic_family_t family; /**< Generic family to plot with */
|
||||||
|
int size; /**< Font size, in points */
|
||||||
|
int weight; /**< Font weight: value in range [100,900] as per CSS */
|
||||||
|
plot_font_flags_t flags; /**< Font flags */
|
||||||
|
colour background; /**< Background colour to blend to, if appropriate */
|
||||||
|
colour foreground; /**< Colour of text */
|
||||||
|
} plot_font_style_t;
|
||||||
|
|
||||||
/* global fill styles */
|
/* global fill styles */
|
||||||
extern plot_style_t *plot_style_fill_white;
|
extern plot_style_t *plot_style_fill_white;
|
||||||
extern plot_style_t *plot_style_fill_red;
|
extern plot_style_t *plot_style_fill_red;
|
||||||
@ -98,4 +137,7 @@ extern plot_style_t *plot_style_stroke_wblobc;
|
|||||||
extern plot_style_t *plot_style_stroke_darkwbasec;
|
extern plot_style_t *plot_style_stroke_darkwbasec;
|
||||||
extern plot_style_t *plot_style_stroke_lightwbasec;
|
extern plot_style_t *plot_style_stroke_lightwbasec;
|
||||||
|
|
||||||
|
/* Default font style */
|
||||||
|
extern plot_font_style_t const * const plot_style_font;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -115,8 +115,8 @@ struct plotter_table {
|
|||||||
bitmap_flags_t flags);
|
bitmap_flags_t flags);
|
||||||
|
|
||||||
/* text */
|
/* text */
|
||||||
bool (*text)(int x, int y, const struct css_style *style,
|
bool (*text)(int x, int y, const char *text, size_t length,
|
||||||
const char *text, size_t length, colour bg, colour c);
|
const plot_font_style_t *fstyle);
|
||||||
|
|
||||||
/* optional callbacks */
|
/* optional callbacks */
|
||||||
bool (*group_start)(const char *name); /**< optional, may be NULL */
|
bool (*group_start)(const char *name); /**< optional, may be NULL */
|
||||||
|
@ -47,15 +47,15 @@
|
|||||||
static bool haru_nsfont_init(HPDF_Doc *pdf, HPDF_Page *page,
|
static bool haru_nsfont_init(HPDF_Doc *pdf, HPDF_Page *page,
|
||||||
const char *string, char **string_nt, int length);
|
const char *string, char **string_nt, int length);
|
||||||
|
|
||||||
static bool haru_nsfont_width(const struct css_style *style,
|
static bool haru_nsfont_width(const plot_font_style_t *fstyle,
|
||||||
const char *string, size_t length,
|
const char *string, size_t length,
|
||||||
int *width);
|
int *width);
|
||||||
|
|
||||||
static bool haru_nsfont_position_in_string(const struct css_style *style,
|
static bool haru_nsfont_position_in_string(const plot_font_style_t *fstyle,
|
||||||
const char *string, size_t length,
|
const char *string, size_t length,
|
||||||
int x, size_t *char_offset, int *actual_x);
|
int x, size_t *char_offset, int *actual_x);
|
||||||
|
|
||||||
static bool haru_nsfont_split(const struct css_style *style,
|
static bool haru_nsfont_split(const plot_font_style_t *fstyle,
|
||||||
const char *string, size_t length,
|
const char *string, size_t length,
|
||||||
int x, size_t *char_offset, int *actual_x);
|
int x, size_t *char_offset, int *actual_x);
|
||||||
|
|
||||||
@ -113,14 +113,13 @@ static bool haru_nsfont_init(HPDF_Doc *pdf, HPDF_Page *page,
|
|||||||
/**
|
/**
|
||||||
* Measure the width of a string.
|
* Measure the width of a string.
|
||||||
*
|
*
|
||||||
* \param style css_style for this text, with style->font_size.size ==
|
* \param fstyle style for this text
|
||||||
* CSS_FONT_SIZE_LENGTH
|
|
||||||
* \param string string to measure (no UTF-8 currently)
|
* \param string string to measure (no UTF-8 currently)
|
||||||
* \param length length of string
|
* \param length length of string
|
||||||
* \param width updated to width of string[0..length]
|
* \param width updated to width of string[0..length]
|
||||||
* \return true on success, false on error and error reported
|
* \return true on success, false on error and error reported
|
||||||
*/
|
*/
|
||||||
bool haru_nsfont_width(const struct css_style *style,
|
bool haru_nsfont_width(const plot_font_style_t *fstyle,
|
||||||
const char *string, size_t length,
|
const char *string, size_t length,
|
||||||
int *width)
|
int *width)
|
||||||
{
|
{
|
||||||
@ -137,7 +136,7 @@ bool haru_nsfont_width(const struct css_style *style,
|
|||||||
if (!haru_nsfont_init(&pdf, &page, string, &string_nt, length))
|
if (!haru_nsfont_init(&pdf, &page, string, &string_nt, length))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!haru_nsfont_apply_style(style, pdf, page, NULL, NULL)) {
|
if (!haru_nsfont_apply_style(fstyle, pdf, page, NULL, NULL)) {
|
||||||
free(string_nt);
|
free(string_nt);
|
||||||
HPDF_Free(pdf);
|
HPDF_Free(pdf);
|
||||||
return false;
|
return false;
|
||||||
@ -159,8 +158,7 @@ bool haru_nsfont_width(const struct css_style *style,
|
|||||||
/**
|
/**
|
||||||
* Find the position in a string where an x coordinate falls.
|
* Find the position in a string where an x coordinate falls.
|
||||||
*
|
*
|
||||||
* \param style css_style for this text, with style->font_size.size ==
|
* \param fstyle style for this text
|
||||||
* CSS_FONT_SIZE_LENGTH
|
|
||||||
* \param string string to measure (no UTF-8 currently)
|
* \param string string to measure (no UTF-8 currently)
|
||||||
* \param length length of string
|
* \param length length of string
|
||||||
* \param x x coordinate to search for
|
* \param x x coordinate to search for
|
||||||
@ -169,7 +167,7 @@ bool haru_nsfont_width(const struct css_style *style,
|
|||||||
* \return true on success, false on error and error reported
|
* \return true on success, false on error and error reported
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool haru_nsfont_position_in_string(const struct css_style *style,
|
bool haru_nsfont_position_in_string(const plot_font_style_t *fstyle,
|
||||||
const char *string, size_t length,
|
const char *string, size_t length,
|
||||||
int x, size_t *char_offset, int *actual_x)
|
int x, size_t *char_offset, int *actual_x)
|
||||||
{
|
{
|
||||||
@ -183,7 +181,7 @@ bool haru_nsfont_position_in_string(const struct css_style *style,
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (HPDF_Page_SetWidth(page, x) != HPDF_OK
|
if (HPDF_Page_SetWidth(page, x) != HPDF_OK
|
||||||
|| !haru_nsfont_apply_style(style, pdf, page, NULL, NULL)) {
|
|| !haru_nsfont_apply_style(fstyle, pdf, page, NULL, NULL)) {
|
||||||
free(string_nt);
|
free(string_nt);
|
||||||
HPDF_Free(pdf);
|
HPDF_Free(pdf);
|
||||||
return false;
|
return false;
|
||||||
@ -218,7 +216,7 @@ bool haru_nsfont_position_in_string(const struct css_style *style,
|
|||||||
/**
|
/**
|
||||||
* Find where to split a string to make it fit a width.
|
* Find where to split a string to make it fit a width.
|
||||||
*
|
*
|
||||||
* \param style css_style for this text, with style->font_size.size ==
|
* \param fstyle css_style for this text, with style->font_size.size ==
|
||||||
* CSS_FONT_SIZE_LENGTH
|
* CSS_FONT_SIZE_LENGTH
|
||||||
* \param string string to measure (no UTF-8 currently)
|
* \param string string to measure (no UTF-8 currently)
|
||||||
* \param length length of string
|
* \param length length of string
|
||||||
@ -228,7 +226,7 @@ bool haru_nsfont_position_in_string(const struct css_style *style,
|
|||||||
* \return true on success, false on error and error reported
|
* \return true on success, false on error and error reported
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool haru_nsfont_split(const struct css_style *style,
|
bool haru_nsfont_split(const plot_font_style_t *fstyle,
|
||||||
const char *string, size_t length,
|
const char *string, size_t length,
|
||||||
int x, size_t *char_offset, int *actual_x)
|
int x, size_t *char_offset, int *actual_x)
|
||||||
{
|
{
|
||||||
@ -243,7 +241,7 @@ bool haru_nsfont_split(const struct css_style *style,
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (HPDF_Page_SetWidth(page, x) != HPDF_OK
|
if (HPDF_Page_SetWidth(page, x) != HPDF_OK
|
||||||
|| !haru_nsfont_apply_style(style, pdf, page, NULL, NULL)) {
|
|| !haru_nsfont_apply_style(fstyle, pdf, page, NULL, NULL)) {
|
||||||
free(string_nt);
|
free(string_nt);
|
||||||
HPDF_Free(pdf);
|
HPDF_Free(pdf);
|
||||||
return false;
|
return false;
|
||||||
@ -268,77 +266,67 @@ bool haru_nsfont_split(const struct css_style *style,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply css_style to a Haru HPDF_Page
|
* Apply font style to a Haru HPDF_Page
|
||||||
*
|
*
|
||||||
* \param style css_style for this page, with style->font_size.size ==
|
* \param style plot style for this page
|
||||||
* CSS_FONT_SIZE_LENGTH
|
|
||||||
* \param doc document owning the page
|
* \param doc document owning the page
|
||||||
* \param page the page to apply the style to
|
* \param page the page to apply the style to
|
||||||
* \param font if this is non NULL it is updated to the font based
|
* \param font if this is non NULL it is updated to the font based
|
||||||
* on given CSS style style
|
* on given style
|
||||||
* \param font_size if this is non NULL it is updated to the font size
|
* \param font_size if this is non NULL it is updated to the font size
|
||||||
* based on given CSS style
|
* based on given style
|
||||||
* \return true on success, false on error and error reported
|
* \return true on success, false on error and error reported
|
||||||
*
|
*
|
||||||
* When both font and font_size are NULL, the HPDF_Page is updated for given
|
* When both font and font_size are NULL, the HPDF_Page is updated for given
|
||||||
* CSS style, otherwise it is left to the called to do this.
|
* style, otherwise it is left to the called to do this.
|
||||||
*/
|
*/
|
||||||
bool haru_nsfont_apply_style(const struct css_style *style,
|
bool haru_nsfont_apply_style(const plot_font_style_t *fstyle,
|
||||||
HPDF_Doc doc, HPDF_Page page,
|
HPDF_Doc doc, HPDF_Page page,
|
||||||
HPDF_Font *font, HPDF_REAL *font_size)
|
HPDF_Font *font, HPDF_REAL *font_size)
|
||||||
{
|
{
|
||||||
HPDF_Font pdf_font;
|
HPDF_Font pdf_font;
|
||||||
HPDF_REAL size;
|
HPDF_REAL size;
|
||||||
char font_name[50];
|
char font_name[50];
|
||||||
bool roman;
|
bool roman = false;
|
||||||
bool bold;
|
bool bold = false;
|
||||||
bool styled;
|
bool styled = false;
|
||||||
|
|
||||||
roman = false;
|
|
||||||
bold = false;
|
|
||||||
styled = false;
|
|
||||||
|
|
||||||
/*TODO: style handling, we are mapping the
|
/*TODO: style handling, we are mapping the
|
||||||
styles on the basic 14 fonts only
|
styles on the basic 14 fonts only
|
||||||
*/
|
*/
|
||||||
switch (style->font_family) {
|
switch (fstyle->family) {
|
||||||
case CSS_FONT_FAMILY_SERIF:
|
case PLOT_FONT_FAMILY_SERIF:
|
||||||
strcpy(font_name, "Times");
|
strcpy(font_name, "Times");
|
||||||
roman = true;
|
roman = true;
|
||||||
break;
|
break;
|
||||||
case CSS_FONT_FAMILY_MONOSPACE:
|
case PLOT_FONT_FAMILY_MONOSPACE:
|
||||||
strcpy(font_name, "Courier");
|
strcpy(font_name, "Courier");
|
||||||
break;
|
break;
|
||||||
case CSS_FONT_FAMILY_SANS_SERIF:
|
case PLOT_FONT_FAMILY_SANS_SERIF:
|
||||||
strcpy(font_name, "Helvetica");
|
strcpy(font_name, "Helvetica");
|
||||||
break;
|
break;
|
||||||
case CSS_FONT_FAMILY_CURSIVE:
|
case PLOT_FONT_FAMILY_CURSIVE:
|
||||||
case CSS_FONT_FAMILY_FANTASY:
|
case PLOT_FONT_FAMILY_FANTASY:
|
||||||
default:
|
default:
|
||||||
strcpy(font_name, "Times");
|
strcpy(font_name, "Times");
|
||||||
roman=true;
|
roman=true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (style->font_weight == CSS_FONT_WEIGHT_BOLD) {
|
if (fstyle->weight == 700) {
|
||||||
strcat(font_name, "-Bold");
|
strcat(font_name, "-Bold");
|
||||||
bold = true;
|
bold = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (style->font_style) {
|
if ((fstyle->flags & FONTF_ITALIC) || (fstyle->flags & FONTF_OBLIQUE)) {
|
||||||
case CSS_FONT_STYLE_ITALIC:
|
if (!bold)
|
||||||
case CSS_FONT_STYLE_OBLIQUE:
|
strcat(font_name,"-");
|
||||||
if (!bold)
|
if (roman)
|
||||||
strcat(font_name,"-");
|
strcat(font_name,"Italic");
|
||||||
if (roman)
|
else
|
||||||
strcat(font_name,"Italic");
|
strcat(font_name,"Oblique");
|
||||||
else
|
|
||||||
strcat(font_name,"Oblique");
|
|
||||||
|
|
||||||
styled = true;
|
styled = true;
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (roman && !styled && !bold)
|
if (roman && !styled && !bold)
|
||||||
@ -347,11 +335,8 @@ bool haru_nsfont_apply_style(const struct css_style *style,
|
|||||||
#ifdef FONT_HARU_DEBUG
|
#ifdef FONT_HARU_DEBUG
|
||||||
LOG(("Setting font: %s", font_name));
|
LOG(("Setting font: %s", font_name));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (style->font_size.value.length.unit == CSS_UNIT_PX)
|
size = fstyle->size;
|
||||||
size = style->font_size.value.length.value;
|
|
||||||
else
|
|
||||||
size = css_len2pt(&style->font_size.value.length, style);
|
|
||||||
|
|
||||||
if (font != NULL)
|
if (font != NULL)
|
||||||
size *= pdf_text_scale;
|
size *= pdf_text_scale;
|
||||||
|
@ -27,8 +27,9 @@
|
|||||||
#include <hpdf.h>
|
#include <hpdf.h>
|
||||||
|
|
||||||
#include "render/font.h"
|
#include "render/font.h"
|
||||||
|
#include "desktop/plot_style.h"
|
||||||
|
|
||||||
bool haru_nsfont_apply_style(const struct css_style *style,
|
bool haru_nsfont_apply_style(const plot_font_style_t *fstyle,
|
||||||
HPDF_Doc doc, HPDF_Page page,
|
HPDF_Doc doc, HPDF_Page page,
|
||||||
HPDF_Font *font, HPDF_REAL *font_size);
|
HPDF_Font *font, HPDF_REAL *font_size);
|
||||||
|
|
||||||
|
@ -50,8 +50,8 @@ static bool pdf_plot_line(int x0, int y0, int x1, int y1, const plot_style_t *ps
|
|||||||
static bool pdf_plot_polygon(const int *p, unsigned int n, const plot_style_t *style);
|
static bool pdf_plot_polygon(const int *p, unsigned int n, const plot_style_t *style);
|
||||||
static bool pdf_plot_clip(int clip_x0, int clip_y0,
|
static bool pdf_plot_clip(int clip_x0, int clip_y0,
|
||||||
int clip_x1, int clip_y1);
|
int clip_x1, int clip_y1);
|
||||||
static bool pdf_plot_text(int x, int y, const struct css_style *style,
|
static bool pdf_plot_text(int x, int y, const char *text, size_t length,
|
||||||
const char *text, size_t length, colour bg, colour c);
|
const plot_font_style_t *fstyle);
|
||||||
static bool pdf_plot_disc(int x, int y, int radius, const plot_style_t *style);
|
static bool pdf_plot_disc(int x, int y, int radius, const plot_style_t *style);
|
||||||
static bool pdf_plot_arc(int x, int y, int radius, int angle1, int angle2,
|
static bool pdf_plot_arc(int x, int y, int radius, int angle1, int angle2,
|
||||||
const plot_style_t *style);
|
const plot_style_t *style);
|
||||||
@ -285,8 +285,8 @@ bool pdf_plot_clip(int clip_x0, int clip_y0, int clip_x1, int clip_y1)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool pdf_plot_text(int x, int y, const struct css_style *style,
|
bool pdf_plot_text(int x, int y, const char *text, size_t length,
|
||||||
const char *text, size_t length, colour bg, colour c)
|
const plot_font_style_t *fstyle)
|
||||||
{
|
{
|
||||||
#ifdef PDF_DEBUG
|
#ifdef PDF_DEBUG
|
||||||
LOG((". %d %d %.*s", x, y, (int)length, text));
|
LOG((". %d %d %.*s", x, y, (int)length, text));
|
||||||
@ -298,9 +298,10 @@ bool pdf_plot_text(int x, int y, const struct css_style *style,
|
|||||||
if (length == 0)
|
if (length == 0)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
apply_clip_and_mode(true, c, NS_TRANSPARENT, 0., DashPattern_eNone);
|
apply_clip_and_mode(true, fstyle->foreground, NS_TRANSPARENT, 0.,
|
||||||
|
DashPattern_eNone);
|
||||||
|
|
||||||
haru_nsfont_apply_style(style, pdf_doc, pdf_page, &pdf_font, &size);
|
haru_nsfont_apply_style(fstyle, pdf_doc, pdf_page, &pdf_font, &size);
|
||||||
pdfw_gs_font(pdf_page, pdf_font, size);
|
pdfw_gs_font(pdf_page, pdf_font, size);
|
||||||
|
|
||||||
/* FIXME: UTF-8 to current font encoding needs to done. Or the font
|
/* FIXME: UTF-8 to current font encoding needs to done. Or the font
|
||||||
|
@ -609,6 +609,9 @@ bool redraw_handler(const char *text, size_t length, struct box *box,
|
|||||||
struct rdw_info *r = (struct rdw_info*)handle;
|
struct rdw_info *r = (struct rdw_info*)handle;
|
||||||
int width, height, space_width;
|
int width, height, space_width;
|
||||||
int x, y;
|
int x, y;
|
||||||
|
plot_font_style_t fstyle;
|
||||||
|
|
||||||
|
font_plot_style_from_css(box->style, &fstyle);
|
||||||
|
|
||||||
/* \todo - it should be possible to reduce the redrawn area by
|
/* \todo - it should be possible to reduce the redrawn area by
|
||||||
* considering the 'text', 'length' and 'space' parameters */
|
* considering the 'text', 'length' and 'space' parameters */
|
||||||
@ -618,7 +621,7 @@ bool redraw_handler(const char *text, size_t length, struct box *box,
|
|||||||
height = box->padding[TOP] + box->height + box->padding[BOTTOM];
|
height = box->padding[TOP] + box->height + box->padding[BOTTOM];
|
||||||
|
|
||||||
if (box->type == BOX_TEXT && box->space &&
|
if (box->type == BOX_TEXT && box->space &&
|
||||||
nsfont.font_width(box->style, " ", 1, &space_width))
|
nsfont.font_width(&fstyle, " ", 1, &space_width))
|
||||||
width += space_width;
|
width += space_width;
|
||||||
|
|
||||||
if (r->inited) {
|
if (r->inited) {
|
||||||
|
@ -96,7 +96,7 @@ struct text_area {
|
|||||||
int selection_start; /**< Character index of sel start(inclusive) */
|
int selection_start; /**< Character index of sel start(inclusive) */
|
||||||
int selection_end; /**< Character index of sel end(exclusive) */
|
int selection_end; /**< Character index of sel end(exclusive) */
|
||||||
|
|
||||||
struct css_style *style; /**< Text style */
|
plot_font_style_t fstyle; /**< Text style */
|
||||||
|
|
||||||
int line_count; /**< Count of lines */
|
int line_count; /**< Count of lines */
|
||||||
#define LINE_CHUNK_SIZE 16
|
#define LINE_CHUNK_SIZE 16
|
||||||
@ -182,15 +182,8 @@ struct text_area *textarea_create(int x, int y, int width, int height,
|
|||||||
ret->text_alloc = 64;
|
ret->text_alloc = 64;
|
||||||
ret->text_len = 1;
|
ret->text_len = 1;
|
||||||
ret->text_utf8_len = 0;
|
ret->text_utf8_len = 0;
|
||||||
|
|
||||||
ret->style = malloc(sizeof(struct css_style));
|
font_plot_style_from_css(style, &ret->fstyle);
|
||||||
if (ret->style == NULL) {
|
|
||||||
LOG(("malloc failed"));
|
|
||||||
free(ret->text);
|
|
||||||
free(ret);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
memcpy(ret->style, style, sizeof(struct css_style));
|
|
||||||
ret->line_height = css_len2px(&(style->line_height.value.length),
|
ret->line_height = css_len2px(&(style->line_height.value.length),
|
||||||
style);
|
style);
|
||||||
|
|
||||||
@ -232,7 +225,6 @@ void textarea_set_position(struct text_area *ta, int x, int y)
|
|||||||
void textarea_destroy(struct text_area *ta)
|
void textarea_destroy(struct text_area *ta)
|
||||||
{
|
{
|
||||||
free(ta->text);
|
free(ta->text);
|
||||||
free(ta->style);
|
|
||||||
free(ta->lines);
|
free(ta->lines);
|
||||||
free(ta);
|
free(ta);
|
||||||
}
|
}
|
||||||
@ -448,8 +440,8 @@ bool textarea_set_caret(struct text_area *ta, int caret)
|
|||||||
if (caret != -1 && (unsigned)caret > c_len)
|
if (caret != -1 && (unsigned)caret > c_len)
|
||||||
caret = c_len;
|
caret = c_len;
|
||||||
|
|
||||||
height = css_len2px(&(ta->style->font_size.value.length),
|
height = ta->fstyle.size * css_screen_dpi / 72;
|
||||||
ta->style);
|
|
||||||
/* Delete the old caret */
|
/* Delete the old caret */
|
||||||
if (ta->caret_pos.char_off != -1) {
|
if (ta->caret_pos.char_off != -1) {
|
||||||
index = textarea_get_caret(ta);
|
index = textarea_get_caret(ta);
|
||||||
@ -467,7 +459,7 @@ bool textarea_set_caret(struct text_area *ta, int caret)
|
|||||||
ta->text_len, b_off))
|
ta->text_len, b_off))
|
||||||
; /* do nothing */
|
; /* do nothing */
|
||||||
|
|
||||||
nsfont.font_width(ta->style,
|
nsfont.font_width(&ta->fstyle,
|
||||||
ta->text +
|
ta->text +
|
||||||
ta->lines[ta->caret_pos.line].b_start,
|
ta->lines[ta->caret_pos.line].b_start,
|
||||||
b_off - ta->lines[ta->caret_pos.line].b_start,
|
b_off - ta->lines[ta->caret_pos.line].b_start,
|
||||||
@ -516,7 +508,7 @@ bool textarea_set_caret(struct text_area *ta, int caret)
|
|||||||
ta->text_len, b_off))
|
ta->text_len, b_off))
|
||||||
; /* do nothing */
|
; /* do nothing */
|
||||||
|
|
||||||
nsfont.font_width(ta->style,
|
nsfont.font_width(&ta->fstyle,
|
||||||
ta->text +
|
ta->text +
|
||||||
ta->lines[ta->caret_pos.line].b_start,
|
ta->lines[ta->caret_pos.line].b_start,
|
||||||
b_off - ta->lines[ta->caret_pos.line].b_start,
|
b_off - ta->lines[ta->caret_pos.line].b_start,
|
||||||
@ -570,7 +562,7 @@ unsigned int textarea_get_xy_offset(struct text_area *ta, int x, int y)
|
|||||||
if (ta->line_count - 1 < line)
|
if (ta->line_count - 1 < line)
|
||||||
line = ta->line_count - 1;
|
line = ta->line_count - 1;
|
||||||
|
|
||||||
nsfont.font_position_in_string(ta->style,
|
nsfont.font_position_in_string(&ta->fstyle,
|
||||||
ta->text + ta->lines[line].b_start,
|
ta->text + ta->lines[line].b_start,
|
||||||
ta->lines[line].b_length, x, &b_off, &x);
|
ta->lines[line].b_length, x, &b_off, &x);
|
||||||
|
|
||||||
@ -679,7 +671,7 @@ bool textarea_reflow(struct text_area *ta, unsigned int line)
|
|||||||
for (len = ta->text_len - 1, text = ta->text; len > 0;
|
for (len = ta->text_len - 1, text = ta->text; len > 0;
|
||||||
len -= b_off, text += b_off) {
|
len -= b_off, text += b_off) {
|
||||||
|
|
||||||
nsfont.font_split(ta->style, text, len,
|
nsfont.font_split(&ta->fstyle, text, len,
|
||||||
ta->vis_width - MARGIN_LEFT - MARGIN_RIGHT,
|
ta->vis_width - MARGIN_LEFT - MARGIN_RIGHT,
|
||||||
&b_off, &x);
|
&b_off, &x);
|
||||||
|
|
||||||
@ -757,7 +749,6 @@ void textarea_redraw(struct text_area *ta, int x0, int y0, int x1, int y1)
|
|||||||
.fill_colour = BACKGROUND_COL,
|
.fill_colour = BACKGROUND_COL,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
if (x1 < ta->x || x0 > ta->x + ta->vis_width || y1 < ta->y ||
|
if (x1 < ta->x || x0 > ta->x + ta->vis_width || y1 < ta->y ||
|
||||||
y0 > ta->y + ta->vis_height)
|
y0 > ta->y + ta->vis_height)
|
||||||
/* Textarea outside the clipping rectangle */
|
/* Textarea outside the clipping rectangle */
|
||||||
@ -848,7 +839,7 @@ void textarea_redraw(struct text_area *ta, int x0, int y0, int x1, int y1)
|
|||||||
b_start = utf8_next(line_text,
|
b_start = utf8_next(line_text,
|
||||||
line_len,
|
line_len,
|
||||||
b_start);
|
b_start);
|
||||||
nsfont.font_width(ta->style, line_text,
|
nsfont.font_width(&ta->fstyle, line_text,
|
||||||
b_start, &x0);
|
b_start, &x0);
|
||||||
x0 += ta->x + MARGIN_LEFT;
|
x0 += ta->x + MARGIN_LEFT;
|
||||||
}
|
}
|
||||||
@ -872,7 +863,7 @@ void textarea_redraw(struct text_area *ta, int x0, int y0, int x1, int y1)
|
|||||||
b_end = ta->lines[line].b_length;
|
b_end = ta->lines[line].b_length;
|
||||||
|
|
||||||
b_end -= b_start;
|
b_end -= b_start;
|
||||||
nsfont.font_width(ta->style,
|
nsfont.font_width(&ta->fstyle,
|
||||||
&(ta->text[ta->lines[line].b_start +
|
&(ta->text[ta->lines[line].b_start +
|
||||||
b_start]),
|
b_start]),
|
||||||
b_end, &x1);
|
b_end, &x1);
|
||||||
@ -890,14 +881,15 @@ void textarea_redraw(struct text_area *ta, int x0, int y0, int x1, int y1)
|
|||||||
c_pos += c_len;
|
c_pos += c_len;
|
||||||
|
|
||||||
y0 = ta->y + line * ta->line_height + 0.75 * ta->line_height;
|
y0 = ta->y + line * ta->line_height + 0.75 * ta->line_height;
|
||||||
|
|
||||||
plot.text(ta->x + MARGIN_LEFT - ta->scroll_x, y0 - ta->scroll_y,
|
ta->fstyle.background =
|
||||||
ta->style,
|
|
||||||
ta->text + ta->lines[line].b_start,
|
|
||||||
ta->lines[line].b_length,
|
|
||||||
(ta->flags & TEXTAREA_READONLY) ?
|
(ta->flags & TEXTAREA_READONLY) ?
|
||||||
READONLY_BG : BACKGROUND_COL,
|
READONLY_BG : BACKGROUND_COL,
|
||||||
ta->style->color);
|
|
||||||
|
plot.text(ta->x + MARGIN_LEFT - ta->scroll_x, y0 - ta->scroll_y,
|
||||||
|
ta->text + ta->lines[line].b_start,
|
||||||
|
ta->lines[line].b_length,
|
||||||
|
&ta->fstyle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1253,7 +1245,7 @@ bool textarea_scroll_visible(struct text_area *ta)
|
|||||||
b_off = utf8_next(ta->text, ta->text_len, b_off))
|
b_off = utf8_next(ta->text, ta->text_len, b_off))
|
||||||
; /* do nothing */
|
; /* do nothing */
|
||||||
|
|
||||||
nsfont.font_width(ta->style,
|
nsfont.font_width(&ta->fstyle,
|
||||||
ta->text + ta->lines[ta->caret_pos.line].b_start,
|
ta->text + ta->lines[ta->caret_pos.line].b_start,
|
||||||
b_off - ta->lines[ta->caret_pos.line].b_start,
|
b_off - ta->lines[ta->caret_pos.line].b_start,
|
||||||
&x);
|
&x);
|
||||||
|
@ -173,6 +173,7 @@ struct box *textarea_get_position(struct box *textarea, int x, int y,
|
|||||||
* lines. */
|
* lines. */
|
||||||
|
|
||||||
struct box *inline_container, *text_box;
|
struct box *inline_container, *text_box;
|
||||||
|
plot_font_style_t fstyle;
|
||||||
|
|
||||||
inline_container = textarea->children;
|
inline_container = textarea->children;
|
||||||
|
|
||||||
@ -181,8 +182,9 @@ struct box *textarea_get_position(struct box *textarea, int x, int y,
|
|||||||
text_box = inline_container->last;
|
text_box = inline_container->last;
|
||||||
assert(text_box->type == BOX_TEXT);
|
assert(text_box->type == BOX_TEXT);
|
||||||
assert(text_box->text);
|
assert(text_box->text);
|
||||||
|
font_plot_style_from_css(text_box->style, &fstyle);
|
||||||
/** \todo handle errors */
|
/** \todo handle errors */
|
||||||
nsfont.font_position_in_string(text_box->style, text_box->text,
|
nsfont.font_position_in_string(&fstyle, text_box->text,
|
||||||
text_box->length,
|
text_box->length,
|
||||||
(unsigned int)(x - text_box->x),
|
(unsigned int)(x - text_box->x),
|
||||||
(size_t *) pchar_offset, ppixel_offset);
|
(size_t *) pchar_offset, ppixel_offset);
|
||||||
@ -204,7 +206,8 @@ struct box *textarea_get_position(struct box *textarea, int x, int y,
|
|||||||
text_box = inline_container->last;
|
text_box = inline_container->last;
|
||||||
assert(text_box->type == BOX_TEXT);
|
assert(text_box->type == BOX_TEXT);
|
||||||
assert(text_box->text);
|
assert(text_box->text);
|
||||||
nsfont.font_position_in_string(text_box->style,
|
font_plot_style_from_css(text_box->style, &fstyle);
|
||||||
|
nsfont.font_position_in_string(&fstyle,
|
||||||
text_box->text,
|
text_box->text,
|
||||||
text_box->length,
|
text_box->length,
|
||||||
textarea->width,
|
textarea->width,
|
||||||
@ -224,7 +227,8 @@ struct box *textarea_get_position(struct box *textarea, int x, int y,
|
|||||||
}
|
}
|
||||||
assert(text_box->type == BOX_TEXT);
|
assert(text_box->type == BOX_TEXT);
|
||||||
assert(text_box->text);
|
assert(text_box->text);
|
||||||
nsfont.font_position_in_string(text_box->style,
|
font_plot_style_from_css(text_box->style, &fstyle);
|
||||||
|
nsfont.font_position_in_string(&fstyle,
|
||||||
text_box->text,
|
text_box->text,
|
||||||
text_box->length,
|
text_box->length,
|
||||||
(unsigned int)(x - text_box->x),
|
(unsigned int)(x - text_box->x),
|
||||||
@ -321,6 +325,7 @@ bool browser_window_textarea_callback(struct browser_window *bw,
|
|||||||
unsigned int utf8_len;
|
unsigned int utf8_len;
|
||||||
bool scrolled, reflow = false;
|
bool scrolled, reflow = false;
|
||||||
bool selection_exists = bw->sel->defined;
|
bool selection_exists = bw->sel->defined;
|
||||||
|
plot_font_style_t fstyle;
|
||||||
|
|
||||||
/* box_dump(textarea, 0); */
|
/* box_dump(textarea, 0); */
|
||||||
LOG(("key %i at %i in '%.*s'", key, char_offset,
|
LOG(("key %i at %i in '%.*s'", key, char_offset,
|
||||||
@ -762,8 +767,9 @@ bool browser_window_textarea_callback(struct browser_window *bw,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nsfont.font_width(text_box->style, text_box->text,
|
font_plot_style_from_css(text_box->style, &fstyle);
|
||||||
char_offset, &pixel_offset);
|
|
||||||
|
nsfont.font_width(&fstyle, text_box->text, char_offset, &pixel_offset);
|
||||||
|
|
||||||
selection_clear(bw->sel, true);
|
selection_clear(bw->sel, true);
|
||||||
|
|
||||||
@ -813,8 +819,11 @@ void browser_window_input_click(struct browser_window* bw,
|
|||||||
size_t char_offset = 0;
|
size_t char_offset = 0;
|
||||||
int pixel_offset = 0, dx = 0;
|
int pixel_offset = 0, dx = 0;
|
||||||
struct box *text_box = input->children->children;
|
struct box *text_box = input->children->children;
|
||||||
|
plot_font_style_t fstyle;
|
||||||
|
|
||||||
nsfont.font_position_in_string(text_box->style, text_box->text,
|
font_plot_style_from_css(text_box->style, &fstyle);
|
||||||
|
|
||||||
|
nsfont.font_position_in_string(&fstyle, text_box->text,
|
||||||
text_box->length, x - text_box->x,
|
text_box->length, x - text_box->x,
|
||||||
&char_offset, &pixel_offset);
|
&char_offset, &pixel_offset);
|
||||||
assert(char_offset <= text_box->length);
|
assert(char_offset <= text_box->length);
|
||||||
@ -1349,6 +1358,7 @@ bool browser_window_textarea_paste_text(struct browser_window *bw,
|
|||||||
|
|
||||||
if (update) {
|
if (update) {
|
||||||
int box_x, box_y;
|
int box_x, box_y;
|
||||||
|
plot_font_style_t fstyle;
|
||||||
|
|
||||||
/* reflow textarea preserving width and height */
|
/* reflow textarea preserving width and height */
|
||||||
textarea_reflow(bw, textarea, inline_container);
|
textarea_reflow(bw, textarea, inline_container);
|
||||||
@ -1380,7 +1390,9 @@ bool browser_window_textarea_paste_text(struct browser_window *bw,
|
|||||||
textarea->gadget->caret_text_box = text_box;
|
textarea->gadget->caret_text_box = text_box;
|
||||||
textarea->gadget->caret_box_offset = char_offset;
|
textarea->gadget->caret_box_offset = char_offset;
|
||||||
|
|
||||||
nsfont.font_width(text_box->style, text_box->text,
|
font_plot_style_from_css(text_box->style, &fstyle);
|
||||||
|
|
||||||
|
nsfont.font_width(&fstyle, text_box->text,
|
||||||
char_offset, &pixel_offset);
|
char_offset, &pixel_offset);
|
||||||
|
|
||||||
textarea->gadget->caret_pixel_offset = pixel_offset;
|
textarea->gadget->caret_pixel_offset = pixel_offset;
|
||||||
@ -1501,12 +1513,15 @@ void browser_window_textarea_move_caret(struct browser_window *bw, void *p)
|
|||||||
size_t char_offset = textarea->gadget->caret_box_offset;
|
size_t char_offset = textarea->gadget->caret_box_offset;
|
||||||
int pixel_offset;
|
int pixel_offset;
|
||||||
int box_x, box_y;
|
int box_x, box_y;
|
||||||
|
plot_font_style_t fstyle;
|
||||||
|
|
||||||
|
font_plot_style_from_css(text_box->style, &fstyle);
|
||||||
|
|
||||||
box_coords(textarea, &box_x, &box_y);
|
box_coords(textarea, &box_x, &box_y);
|
||||||
box_x -= textarea->scroll_x;
|
box_x -= textarea->scroll_x;
|
||||||
box_y -= textarea->scroll_y;
|
box_y -= textarea->scroll_y;
|
||||||
|
|
||||||
nsfont.font_width(text_box->style, text_box->text,
|
nsfont.font_width(&fstyle, text_box->text,
|
||||||
char_offset, &pixel_offset);
|
char_offset, &pixel_offset);
|
||||||
|
|
||||||
browser_window_place_caret(bw,
|
browser_window_place_caret(bw,
|
||||||
@ -1536,10 +1551,13 @@ void browser_window_input_move_caret(struct browser_window *bw, void *p)
|
|||||||
unsigned int box_offset = input->gadget->caret_box_offset;
|
unsigned int box_offset = input->gadget->caret_box_offset;
|
||||||
int pixel_offset;
|
int pixel_offset;
|
||||||
int box_x, box_y;
|
int box_x, box_y;
|
||||||
|
plot_font_style_t fstyle;
|
||||||
|
|
||||||
|
font_plot_style_from_css(text_box->style, &fstyle);
|
||||||
|
|
||||||
box_coords(input, &box_x, &box_y);
|
box_coords(input, &box_x, &box_y);
|
||||||
|
|
||||||
nsfont.font_width(text_box->style, text_box->text, box_offset,
|
nsfont.font_width(&fstyle, text_box->text, box_offset,
|
||||||
&pixel_offset);
|
&pixel_offset);
|
||||||
|
|
||||||
browser_window_place_caret(bw,
|
browser_window_place_caret(bw,
|
||||||
@ -1572,14 +1590,17 @@ void input_update_display(struct browser_window *bw, struct box *input,
|
|||||||
unsigned pixel_offset;
|
unsigned pixel_offset;
|
||||||
int box_x, box_y;
|
int box_x, box_y;
|
||||||
int dx;
|
int dx;
|
||||||
|
plot_font_style_t fstyle;
|
||||||
|
|
||||||
|
font_plot_style_from_css(text_box->style, &fstyle);
|
||||||
|
|
||||||
if (redraw)
|
if (redraw)
|
||||||
nsfont.font_width(text_box->style, text_box->text, text_box->length,
|
nsfont.font_width(&fstyle, text_box->text, text_box->length,
|
||||||
&text_box->width);
|
&text_box->width);
|
||||||
|
|
||||||
box_coords(input, &box_x, &box_y);
|
box_coords(input, &box_x, &box_y);
|
||||||
|
|
||||||
nsfont.font_width(text_box->style, text_box->text, box_offset,
|
nsfont.font_width(&fstyle, text_box->text, box_offset,
|
||||||
(int *) &pixel_offset);
|
(int *) &pixel_offset);
|
||||||
|
|
||||||
/* Shift text box horizontally, so caret is visible */
|
/* Shift text box horizontally, so caret is visible */
|
||||||
|
@ -39,7 +39,12 @@
|
|||||||
#include "framebuffer/bitmap.h"
|
#include "framebuffer/bitmap.h"
|
||||||
#include "framebuffer/image_data.h"
|
#include "framebuffer/image_data.h"
|
||||||
|
|
||||||
static struct css_style root_style;
|
static plot_font_style_t root_style = {
|
||||||
|
.family = PLOT_FONT_FAMILY_SANS_SERIF,
|
||||||
|
.size = 11,
|
||||||
|
.weight = 400,
|
||||||
|
.flags = FONTF_NONE,
|
||||||
|
};
|
||||||
|
|
||||||
enum fbtk_widgettype_e {
|
enum fbtk_widgettype_e {
|
||||||
FB_WIDGET_TYPE_ROOT = 0,
|
FB_WIDGET_TYPE_ROOT = 0,
|
||||||
@ -601,13 +606,14 @@ fb_redraw_text(fbtk_widget_t *root, fbtk_widget_t *widget, void *pw)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (widget->u.text.text != NULL) {
|
if (widget->u.text.text != NULL) {
|
||||||
|
root_style.background = widget->bg;
|
||||||
|
root_style.foreground = widget->fg;
|
||||||
|
|
||||||
plot.text(bbox.x0 + 3,
|
plot.text(bbox.x0 + 3,
|
||||||
bbox.y0 + 17,
|
bbox.y0 + 17,
|
||||||
&root_style,
|
|
||||||
widget->u.text.text,
|
widget->u.text.text,
|
||||||
strlen(widget->u.text.text),
|
strlen(widget->u.text.text),
|
||||||
widget->bg,
|
&root_style);
|
||||||
widget->fg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nsfb_release(root->u.root.fb, &bbox);
|
nsfb_release(root->u.root.fb, &bbox);
|
||||||
@ -1301,9 +1307,6 @@ fbtk_init(nsfb_t *fb)
|
|||||||
root->y = 0;
|
root->y = 0;
|
||||||
root->u.root.rootw = fbtk_create_window(root, 0, 0, 0, 0);
|
root->u.root.rootw = fbtk_create_window(root, 0, 0, 0, 0);
|
||||||
|
|
||||||
root_style.font_size.value.length.unit = CSS_UNIT_PX;
|
|
||||||
root_style.font_size.value.length.value = 14;
|
|
||||||
|
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -221,91 +221,54 @@ bool fb_font_finalise(void)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void fb_fill_scalar(const struct css_style *style, FTC_Scaler srec)
|
static void fb_fill_scalar(const plot_font_style_t *fstyle, FTC_Scaler srec)
|
||||||
{
|
{
|
||||||
int selected_face = FB_FACE_DEFAULT;
|
int selected_face = FB_FACE_DEFAULT;
|
||||||
|
|
||||||
switch (style->font_family) {
|
switch (fstyle->family) {
|
||||||
/*
|
/*
|
||||||
case CSS_FONT_FAMILY_CURSIVE:
|
case PLOT_FONT_FAMILY_CURSIVE:
|
||||||
break;
|
break;
|
||||||
case CSS_FONT_FAMILY_FANTASY:
|
case PLOT_FONT_FAMILY_FANTASY:
|
||||||
break;
|
break;
|
||||||
*/
|
*/
|
||||||
case CSS_FONT_FAMILY_SERIF:
|
case PLOT_FONT_FAMILY_SERIF:
|
||||||
switch (style->font_weight) {
|
if (fstyle->weight >= 700)
|
||||||
case CSS_FONT_WEIGHT_700:
|
|
||||||
case CSS_FONT_WEIGHT_800:
|
|
||||||
case CSS_FONT_WEIGHT_900:
|
|
||||||
case CSS_FONT_WEIGHT_BOLD:
|
|
||||||
selected_face = FB_FACE_SERIF_BOLD;
|
selected_face = FB_FACE_SERIF_BOLD;
|
||||||
break;
|
else
|
||||||
|
|
||||||
case CSS_FONT_WEIGHT_NORMAL:
|
|
||||||
default:
|
|
||||||
selected_face = FB_FACE_SERIF;
|
selected_face = FB_FACE_SERIF;
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CSS_FONT_FAMILY_MONOSPACE:
|
case PLOT_FONT_FAMILY_MONOSPACE:
|
||||||
selected_face = FB_FACE_MONOSPACE;
|
selected_face = FB_FACE_MONOSPACE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CSS_FONT_FAMILY_SANS_SERIF:
|
case PLOT_FONT_FAMILY_SANS_SERIF:
|
||||||
default:
|
default:
|
||||||
switch (style->font_style) {
|
if ((fstyle->flags & FONTF_ITALIC) ||
|
||||||
case CSS_FONT_STYLE_ITALIC:
|
(fstyle->flags & FONTF_OBLIQUE)) {
|
||||||
switch (style->font_weight) {
|
if (fstyle->weight >= 700)
|
||||||
case CSS_FONT_WEIGHT_700:
|
|
||||||
case CSS_FONT_WEIGHT_800:
|
|
||||||
case CSS_FONT_WEIGHT_900:
|
|
||||||
case CSS_FONT_WEIGHT_BOLD:
|
|
||||||
selected_face = FB_FACE_SANS_SERIF_ITALIC_BOLD;
|
selected_face = FB_FACE_SANS_SERIF_ITALIC_BOLD;
|
||||||
break;
|
else
|
||||||
|
|
||||||
case CSS_FONT_WEIGHT_NORMAL:
|
|
||||||
default:
|
|
||||||
selected_face = FB_FACE_SANS_SERIF_ITALIC;
|
selected_face = FB_FACE_SANS_SERIF_ITALIC;
|
||||||
break;
|
} else {
|
||||||
}
|
if (fstyle->weight >= 700)
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
switch (style->font_weight) {
|
|
||||||
case CSS_FONT_WEIGHT_700:
|
|
||||||
case CSS_FONT_WEIGHT_800:
|
|
||||||
case CSS_FONT_WEIGHT_900:
|
|
||||||
case CSS_FONT_WEIGHT_BOLD:
|
|
||||||
selected_face = FB_FACE_SANS_SERIF_BOLD;
|
selected_face = FB_FACE_SANS_SERIF_BOLD;
|
||||||
break;
|
else
|
||||||
|
|
||||||
case CSS_FONT_WEIGHT_NORMAL:
|
|
||||||
default:
|
|
||||||
selected_face = FB_FACE_SANS_SERIF;
|
selected_face = FB_FACE_SANS_SERIF;
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
srec->face_id = (FTC_FaceID)fb_faces[selected_face];
|
srec->face_id = (FTC_FaceID)fb_faces[selected_face];
|
||||||
|
|
||||||
if (style->font_size.value.length.unit == CSS_UNIT_PX) {
|
srec->width = srec->height = fstyle->size * 64;
|
||||||
srec->width = srec->height = style->font_size.value.length.value;
|
srec->pixel = 0;
|
||||||
srec->pixel = 1;
|
|
||||||
} else {
|
|
||||||
srec->width = srec->height =
|
|
||||||
css_len2pt(&style->font_size.value.length, style) * 64;
|
|
||||||
srec->pixel = 0;
|
|
||||||
|
|
||||||
srec->x_res = srec->y_res = 72;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
srec->x_res = srec->y_res = 72;
|
||||||
}
|
}
|
||||||
|
|
||||||
FT_Glyph fb_getglyph(const struct css_style *style, uint32_t ucs4)
|
FT_Glyph fb_getglyph(const plot_font_style_t *fstyle, uint32_t ucs4)
|
||||||
{
|
{
|
||||||
FT_UInt glyph_index;
|
FT_UInt glyph_index;
|
||||||
FTC_ScalerRec srec;
|
FTC_ScalerRec srec;
|
||||||
@ -313,7 +276,7 @@ FT_Glyph fb_getglyph(const struct css_style *style, uint32_t ucs4)
|
|||||||
FT_Error error;
|
FT_Error error;
|
||||||
fb_faceid_t *fb_face;
|
fb_faceid_t *fb_face;
|
||||||
|
|
||||||
fb_fill_scalar(style, &srec);
|
fb_fill_scalar(fstyle, &srec);
|
||||||
|
|
||||||
fb_face = (fb_faceid_t *)srec.face_id;
|
fb_face = (fb_faceid_t *)srec.face_id;
|
||||||
|
|
||||||
@ -335,14 +298,13 @@ FT_Glyph fb_getglyph(const struct css_style *style, uint32_t ucs4)
|
|||||||
/**
|
/**
|
||||||
* Measure the width of a string.
|
* Measure the width of a string.
|
||||||
*
|
*
|
||||||
* \param style css_style for this text, with style->font_size.size ==
|
* \param fstyle style for this text
|
||||||
* CSS_FONT_SIZE_LENGTH
|
|
||||||
* \param string UTF-8 string to measure
|
* \param string UTF-8 string to measure
|
||||||
* \param length length of string
|
* \param length length of string
|
||||||
* \param width updated to width of string[0..length)
|
* \param width updated to width of string[0..length)
|
||||||
* \return true on success, false on error and error reported
|
* \return true on success, false on error and error reported
|
||||||
*/
|
*/
|
||||||
static bool nsfont_width(const struct css_style *style,
|
static bool nsfont_width(const plot_font_style_t *fstyle,
|
||||||
const char *string, size_t length,
|
const char *string, size_t length,
|
||||||
int *width)
|
int *width)
|
||||||
{
|
{
|
||||||
@ -355,7 +317,7 @@ static bool nsfont_width(const struct css_style *style,
|
|||||||
ucs4 = utf8_to_ucs4(string + nxtchr, length - nxtchr);
|
ucs4 = utf8_to_ucs4(string + nxtchr, length - nxtchr);
|
||||||
nxtchr = utf8_next(string, length, nxtchr);
|
nxtchr = utf8_next(string, length, nxtchr);
|
||||||
|
|
||||||
glyph = fb_getglyph(style, ucs4);
|
glyph = fb_getglyph(fstyle, ucs4);
|
||||||
if (glyph == NULL)
|
if (glyph == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -368,8 +330,7 @@ static bool nsfont_width(const struct css_style *style,
|
|||||||
/**
|
/**
|
||||||
* Find the position in a string where an x coordinate falls.
|
* Find the position in a string where an x coordinate falls.
|
||||||
*
|
*
|
||||||
* \param style css_style for this text, with style->font_size.size ==
|
* \param fstyle style for this text
|
||||||
* CSS_FONT_SIZE_LENGTH
|
|
||||||
* \param string UTF-8 string to measure
|
* \param string UTF-8 string to measure
|
||||||
* \param length length of string
|
* \param length length of string
|
||||||
* \param x x coordinate to search for
|
* \param x x coordinate to search for
|
||||||
@ -378,7 +339,7 @@ static bool nsfont_width(const struct css_style *style,
|
|||||||
* \return true on success, false on error and error reported
|
* \return true on success, false on error and error reported
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static bool nsfont_position_in_string(const struct css_style *style,
|
static bool nsfont_position_in_string(const plot_font_style_t *fstyle,
|
||||||
const char *string, size_t length,
|
const char *string, size_t length,
|
||||||
int x, size_t *char_offset, int *actual_x)
|
int x, size_t *char_offset, int *actual_x)
|
||||||
{
|
{
|
||||||
@ -390,7 +351,7 @@ static bool nsfont_position_in_string(const struct css_style *style,
|
|||||||
while (nxtchr < length) {
|
while (nxtchr < length) {
|
||||||
ucs4 = utf8_to_ucs4(string + nxtchr, length - nxtchr);
|
ucs4 = utf8_to_ucs4(string + nxtchr, length - nxtchr);
|
||||||
|
|
||||||
glyph = fb_getglyph(style, ucs4);
|
glyph = fb_getglyph(fstyle, ucs4);
|
||||||
if (glyph == NULL)
|
if (glyph == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -409,8 +370,7 @@ static bool nsfont_position_in_string(const struct css_style *style,
|
|||||||
/**
|
/**
|
||||||
* Find where to split a string to make it fit a width.
|
* Find where to split a string to make it fit a width.
|
||||||
*
|
*
|
||||||
* \param style css_style for this text, with style->font_size.size ==
|
* \param fstyle style for this text
|
||||||
* CSS_FONT_SIZE_LENGTH
|
|
||||||
* \param string UTF-8 string to measure
|
* \param string UTF-8 string to measure
|
||||||
* \param length length of string
|
* \param length length of string
|
||||||
* \param x width available
|
* \param x width available
|
||||||
@ -423,7 +383,7 @@ static bool nsfont_position_in_string(const struct css_style *style,
|
|||||||
* char_offset == length]
|
* char_offset == length]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static bool nsfont_split(const struct css_style *style,
|
static bool nsfont_split(const plot_font_style_t *fstyle,
|
||||||
const char *string, size_t length,
|
const char *string, size_t length,
|
||||||
int x, size_t *char_offset, int *actual_x)
|
int x, size_t *char_offset, int *actual_x)
|
||||||
{
|
{
|
||||||
@ -437,7 +397,7 @@ static bool nsfont_split(const struct css_style *style,
|
|||||||
while (nxtchr < length) {
|
while (nxtchr < length) {
|
||||||
ucs4 = utf8_to_ucs4(string + nxtchr, length - nxtchr);
|
ucs4 = utf8_to_ucs4(string + nxtchr, length - nxtchr);
|
||||||
|
|
||||||
glyph = fb_getglyph(style, ucs4);
|
glyph = fb_getglyph(fstyle, ucs4);
|
||||||
if (glyph == NULL)
|
if (glyph == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -25,6 +25,6 @@
|
|||||||
|
|
||||||
extern int ft_load_type;
|
extern int ft_load_type;
|
||||||
|
|
||||||
FT_Glyph fb_getglyph(const struct css_style *style, uint32_t ucs4);
|
FT_Glyph fb_getglyph(const plot_font_style_t *fstyle, uint32_t ucs4);
|
||||||
|
|
||||||
#endif /* NETSURF_FB_FONT_FREETYPE_H */
|
#endif /* NETSURF_FB_FONT_FREETYPE_H */
|
||||||
|
@ -34,7 +34,7 @@ bool fb_font_init(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
const struct fb_font_desc*
|
const struct fb_font_desc*
|
||||||
fb_get_font(const struct css_style *style)
|
fb_get_font(const plot_font_style_t *fstyle)
|
||||||
{
|
{
|
||||||
return &font_vga_8x16;
|
return &font_vga_8x16;
|
||||||
}
|
}
|
||||||
@ -56,11 +56,11 @@ utf8_convert_ret utf8_to_local_encoding(const char *string,
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool nsfont_width(const struct css_style *style,
|
static bool nsfont_width(const plot_font_style_t *fstyle,
|
||||||
const char *string, size_t length,
|
const char *string, size_t length,
|
||||||
int *width)
|
int *width)
|
||||||
{
|
{
|
||||||
const struct fb_font_desc* fb_font = fb_get_font(style);
|
const struct fb_font_desc* fb_font = fb_get_font(fstyle);
|
||||||
*width = fb_font->width * utf8_bounded_length(string, length);
|
*width = fb_font->width * utf8_bounded_length(string, length);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -68,8 +68,7 @@ static bool nsfont_width(const struct css_style *style,
|
|||||||
/**
|
/**
|
||||||
* Find the position in a string where an x coordinate falls.
|
* Find the position in a string where an x coordinate falls.
|
||||||
*
|
*
|
||||||
* \param style css_style for this text, with style->font_size.size ==
|
* \param fstyle style for this text
|
||||||
* CSS_FONT_SIZE_LENGTH
|
|
||||||
* \param string UTF-8 string to measure
|
* \param string UTF-8 string to measure
|
||||||
* \param length length of string
|
* \param length length of string
|
||||||
* \param x x coordinate to search for
|
* \param x x coordinate to search for
|
||||||
@ -78,11 +77,11 @@ static bool nsfont_width(const struct css_style *style,
|
|||||||
* \return true on success, false on error and error reported
|
* \return true on success, false on error and error reported
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static bool nsfont_position_in_string(const struct css_style *style,
|
static bool nsfont_position_in_string(const plot_font_style_t *fstyle,
|
||||||
const char *string, size_t length,
|
const char *string, size_t length,
|
||||||
int x, size_t *char_offset, int *actual_x)
|
int x, size_t *char_offset, int *actual_x)
|
||||||
{
|
{
|
||||||
const struct fb_font_desc* fb_font = fb_get_font(style);
|
const struct fb_font_desc* fb_font = fb_get_font(fstyle);
|
||||||
*char_offset = x / fb_font->width;
|
*char_offset = x / fb_font->width;
|
||||||
if (*char_offset > length)
|
if (*char_offset > length)
|
||||||
*char_offset = length;
|
*char_offset = length;
|
||||||
@ -94,8 +93,7 @@ static bool nsfont_position_in_string(const struct css_style *style,
|
|||||||
/**
|
/**
|
||||||
* Find where to split a string to make it fit a width.
|
* Find where to split a string to make it fit a width.
|
||||||
*
|
*
|
||||||
* \param style css_style for this text, with style->font_size.size ==
|
* \param fstyle style for this text
|
||||||
* CSS_FONT_SIZE_LENGTH
|
|
||||||
* \param string UTF-8 string to measure
|
* \param string UTF-8 string to measure
|
||||||
* \param length length of string
|
* \param length length of string
|
||||||
* \param x width available
|
* \param x width available
|
||||||
@ -108,12 +106,12 @@ static bool nsfont_position_in_string(const struct css_style *style,
|
|||||||
* char_offset == length]
|
* char_offset == length]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static bool nsfont_split(const struct css_style *style,
|
static bool nsfont_split(const plot_font_style_t *fstyle,
|
||||||
const char *string, size_t length,
|
const char *string, size_t length,
|
||||||
int x, size_t *char_offset, int *actual_x)
|
int x, size_t *char_offset, int *actual_x)
|
||||||
{
|
{
|
||||||
|
|
||||||
const struct fb_font_desc* fb_font = fb_get_font(style);
|
const struct fb_font_desc* fb_font = fb_get_font(fstyle);
|
||||||
*char_offset = x / fb_font->width;
|
*char_offset = x / fb_font->width;
|
||||||
if (*char_offset > length) {
|
if (*char_offset > length) {
|
||||||
*char_offset = length;
|
*char_offset = length;
|
||||||
|
@ -28,7 +28,7 @@ struct fb_font_desc {
|
|||||||
|
|
||||||
extern const struct fb_font_desc font_vga_8x16;
|
extern const struct fb_font_desc font_vga_8x16;
|
||||||
|
|
||||||
extern const struct fb_font_desc* fb_get_font(const struct css_style *style);
|
extern const struct fb_font_desc* fb_get_font(const plot_font_style_t *fstyle);
|
||||||
|
|
||||||
extern utf8_convert_ret utf8_to_font_encoding(const struct fb_font_desc* font,
|
extern utf8_convert_ret utf8_to_font_encoding(const struct fb_font_desc* font,
|
||||||
const char *string,
|
const char *string,
|
||||||
|
@ -42,7 +42,6 @@
|
|||||||
/* netsurf framebuffer library handle */
|
/* netsurf framebuffer library handle */
|
||||||
static nsfb_t *nsfb;
|
static nsfb_t *nsfb;
|
||||||
|
|
||||||
#ifdef FB_USE_FREETYPE
|
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
framebuffer_plot_disc(int x, int y, int radius, const plot_style_t *style)
|
framebuffer_plot_disc(int x, int y, int radius, const plot_style_t *style)
|
||||||
@ -75,8 +74,9 @@ static bool framebuffer_plot_polygon(const int *p, unsigned int n, const plot_st
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool framebuffer_plot_text(int x, int y, const struct css_style *style,
|
#ifdef FB_USE_FREETYPE
|
||||||
const char *text, size_t length, colour bg, colour c)
|
static bool framebuffer_plot_text(int x, int y, const char *text, size_t length,
|
||||||
|
const plot_font_style_t *fstyle)
|
||||||
{
|
{
|
||||||
uint32_t ucs4;
|
uint32_t ucs4;
|
||||||
size_t nxtchr = 0;
|
size_t nxtchr = 0;
|
||||||
@ -88,7 +88,7 @@ static bool framebuffer_plot_text(int x, int y, const struct css_style *style,
|
|||||||
ucs4 = utf8_to_ucs4(text + nxtchr, length - nxtchr);
|
ucs4 = utf8_to_ucs4(text + nxtchr, length - nxtchr);
|
||||||
nxtchr = utf8_next(text, length, nxtchr);
|
nxtchr = utf8_next(text, length, nxtchr);
|
||||||
|
|
||||||
glyph = fb_getglyph(style, ucs4);
|
glyph = fb_getglyph(fstyle, ucs4);
|
||||||
if (glyph == NULL)
|
if (glyph == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -106,13 +106,13 @@ static bool framebuffer_plot_text(int x, int y, const struct css_style *style,
|
|||||||
&loc,
|
&loc,
|
||||||
bglyph->bitmap.buffer,
|
bglyph->bitmap.buffer,
|
||||||
bglyph->bitmap.pitch,
|
bglyph->bitmap.pitch,
|
||||||
c);
|
fstyle->foreground);
|
||||||
} else {
|
} else {
|
||||||
nsfb_plot_glyph8(nsfb,
|
nsfb_plot_glyph8(nsfb,
|
||||||
&loc,
|
&loc,
|
||||||
bglyph->bitmap.buffer,
|
bglyph->bitmap.buffer,
|
||||||
bglyph->bitmap.pitch,
|
bglyph->bitmap.pitch,
|
||||||
c);
|
fstyle->foreground);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
x += glyph->advance.x >> 16;
|
x += glyph->advance.x >> 16;
|
||||||
@ -122,10 +122,10 @@ static bool framebuffer_plot_text(int x, int y, const struct css_style *style,
|
|||||||
|
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
static bool framebuffer_plot_text(int x, int y, const struct css_style *style,
|
static bool framebuffer_plot_text(int x, int y, const char *text, size_t length,
|
||||||
const char *text, size_t length, colour bg, colour c)
|
const plot_font_style_t *fstyle)
|
||||||
{
|
{
|
||||||
const struct fb_font_desc* fb_font = fb_get_font(style);
|
const struct fb_font_desc* fb_font = fb_get_font(fstyle);
|
||||||
const uint32_t *chrp;
|
const uint32_t *chrp;
|
||||||
char *buffer = NULL;
|
char *buffer = NULL;
|
||||||
int chr;
|
int chr;
|
||||||
@ -152,7 +152,7 @@ static bool framebuffer_plot_text(int x, int y, const struct css_style *style,
|
|||||||
loc.y1 = loc.y0 + fb_font->height;
|
loc.y1 = loc.y0 + fb_font->height;
|
||||||
|
|
||||||
chrp = fb_font->data + ((unsigned char)buffer[chr] * fb_font->height);
|
chrp = fb_font->data + ((unsigned char)buffer[chr] * fb_font->height);
|
||||||
nsfb_plot_glyph1(nsfb, &loc, (uint8_t *)chrp, 32, c);
|
nsfb_plot_glyph1(nsfb, &loc, (uint8_t *)chrp, 32, fstyle->foreground);
|
||||||
|
|
||||||
x+=fb_font->width;
|
x+=fb_font->width;
|
||||||
|
|
||||||
|
143
gtk/font_pango.c
143
gtk/font_pango.c
@ -37,17 +37,17 @@
|
|||||||
/* Until we can consider the descenders etc, we need to not render using cairo */
|
/* Until we can consider the descenders etc, we need to not render using cairo */
|
||||||
#undef CAIRO_VERSION
|
#undef CAIRO_VERSION
|
||||||
|
|
||||||
static bool nsfont_width(const struct css_style *style,
|
static bool nsfont_width(const plot_font_style_t *fstyle,
|
||||||
const char *string, size_t length,
|
const char *string, size_t length,
|
||||||
int *width);
|
int *width);
|
||||||
|
|
||||||
static bool nsfont_position_in_string(const struct css_style *style,
|
static bool nsfont_position_in_string(const plot_font_style_t *fstyle,
|
||||||
const char *string, size_t length,
|
const char *string, size_t length,
|
||||||
int x, size_t *char_offset, int *actual_x);
|
int x, size_t *char_offset, int *actual_x);
|
||||||
|
|
||||||
static bool nsfont_split(const struct css_style *style,
|
static bool nsfont_split(const plot_font_style_t *style,
|
||||||
const char *string, size_t length,
|
const char *string, size_t length,
|
||||||
int x, size_t *char_offset, int *actual_x);
|
int x, size_t *char_offset, int *actual_x);
|
||||||
|
|
||||||
const struct font_functions nsfont = {
|
const struct font_functions nsfont = {
|
||||||
nsfont_width,
|
nsfont_width,
|
||||||
@ -62,15 +62,14 @@ const struct font_functions nsfont = {
|
|||||||
/**
|
/**
|
||||||
* Measure the width of a string.
|
* Measure the width of a string.
|
||||||
*
|
*
|
||||||
* \param style css_style for this text, with style->font_size.size ==
|
* \param fstyle plot style for this text
|
||||||
* CSS_FONT_SIZE_LENGTH
|
|
||||||
* \param string UTF-8 string to measure
|
* \param string UTF-8 string to measure
|
||||||
* \param length length of string
|
* \param length length of string
|
||||||
* \param width updated to width of string[0..length)
|
* \param width updated to width of string[0..length)
|
||||||
* \return true on success, false on error and error reported
|
* \return true on success, false on error and error reported
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool nsfont_width(const struct css_style *style,
|
bool nsfont_width(const plot_font_style_t *fstyle,
|
||||||
const char *string, size_t length,
|
const char *string, size_t length,
|
||||||
int *width)
|
int *width)
|
||||||
{
|
{
|
||||||
@ -83,7 +82,7 @@ bool nsfont_width(const struct css_style *style,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
desc = nsfont_style_to_description(style);
|
desc = nsfont_style_to_description(fstyle);
|
||||||
context = gdk_pango_context_get();
|
context = gdk_pango_context_get();
|
||||||
layout = pango_layout_new(context);
|
layout = pango_layout_new(context);
|
||||||
pango_layout_set_font_description(layout, desc);
|
pango_layout_set_font_description(layout, desc);
|
||||||
@ -102,8 +101,7 @@ bool nsfont_width(const struct css_style *style,
|
|||||||
/**
|
/**
|
||||||
* Find the position in a string where an x coordinate falls.
|
* Find the position in a string where an x coordinate falls.
|
||||||
*
|
*
|
||||||
* \param style css_style for this text, with style->font_size.size ==
|
* \param fstyle plot style for this text
|
||||||
* CSS_FONT_SIZE_LENGTH
|
|
||||||
* \param string UTF-8 string to measure
|
* \param string UTF-8 string to measure
|
||||||
* \param length length of string
|
* \param length length of string
|
||||||
* \param x x coordinate to search for
|
* \param x x coordinate to search for
|
||||||
@ -112,7 +110,7 @@ bool nsfont_width(const struct css_style *style,
|
|||||||
* \return true on success, false on error and error reported
|
* \return true on success, false on error and error reported
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool nsfont_position_in_string(const struct css_style *style,
|
bool nsfont_position_in_string(const plot_font_style_t *fstyle,
|
||||||
const char *string, size_t length,
|
const char *string, size_t length,
|
||||||
int x, size_t *char_offset, int *actual_x)
|
int x, size_t *char_offset, int *actual_x)
|
||||||
{
|
{
|
||||||
@ -122,7 +120,7 @@ bool nsfont_position_in_string(const struct css_style *style,
|
|||||||
PangoLayout *layout;
|
PangoLayout *layout;
|
||||||
PangoRectangle pos;
|
PangoRectangle pos;
|
||||||
|
|
||||||
desc = nsfont_style_to_description(style);
|
desc = nsfont_style_to_description(fstyle);
|
||||||
context = gdk_pango_context_get();
|
context = gdk_pango_context_get();
|
||||||
layout = pango_layout_new(context);
|
layout = pango_layout_new(context);
|
||||||
pango_layout_set_font_description(layout, desc);
|
pango_layout_set_font_description(layout, desc);
|
||||||
@ -149,8 +147,7 @@ bool nsfont_position_in_string(const struct css_style *style,
|
|||||||
/**
|
/**
|
||||||
* Find where to split a string to make it fit a width.
|
* Find where to split a string to make it fit a width.
|
||||||
*
|
*
|
||||||
* \param style css_style for this text, with style->font_size.size ==
|
* \param fstyle plot style for this text
|
||||||
* CSS_FONT_SIZE_LENGTH
|
|
||||||
* \param string UTF-8 string to measure
|
* \param string UTF-8 string to measure
|
||||||
* \param length length of string
|
* \param length length of string
|
||||||
* \param x width available
|
* \param x width available
|
||||||
@ -163,7 +160,7 @@ bool nsfont_position_in_string(const struct css_style *style,
|
|||||||
* char_offset == length]
|
* char_offset == length]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool nsfont_split(const struct css_style *style,
|
bool nsfont_split(const plot_font_style_t *fstyle,
|
||||||
const char *string, size_t length,
|
const char *string, size_t length,
|
||||||
int x, size_t *char_offset, int *actual_x)
|
int x, size_t *char_offset, int *actual_x)
|
||||||
{
|
{
|
||||||
@ -175,7 +172,7 @@ bool nsfont_split(const struct css_style *style,
|
|||||||
PangoLayoutIter *iter;
|
PangoLayoutIter *iter;
|
||||||
PangoRectangle rect;
|
PangoRectangle rect;
|
||||||
|
|
||||||
desc = nsfont_style_to_description(style);
|
desc = nsfont_style_to_description(fstyle);
|
||||||
context = gdk_pango_context_get();
|
context = gdk_pango_context_get();
|
||||||
layout = pango_layout_new(context);
|
layout = pango_layout_new(context);
|
||||||
pango_layout_set_font_description(layout, desc);
|
pango_layout_set_font_description(layout, desc);
|
||||||
@ -206,19 +203,16 @@ bool nsfont_split(const struct css_style *style,
|
|||||||
/**
|
/**
|
||||||
* Render a string.
|
* Render a string.
|
||||||
*
|
*
|
||||||
* \param style css_style for this text, with style->font_size.size ==
|
|
||||||
* CSS_FONT_SIZE_LENGTH
|
|
||||||
* \param string UTF-8 string to measure
|
|
||||||
* \param length length of string
|
|
||||||
* \param x x coordinate
|
* \param x x coordinate
|
||||||
* \param y y coordinate
|
* \param y y coordinate
|
||||||
* \param c colour for text
|
* \param string UTF-8 string to measure
|
||||||
|
* \param length length of string
|
||||||
|
* \param style plot style for this text
|
||||||
* \return true on success, false on error and error reported
|
* \return true on success, false on error and error reported
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool nsfont_paint(const struct css_style *style,
|
bool nsfont_paint(int x, int y, const char *string, size_t length,
|
||||||
const char *string, size_t length,
|
const plot_font_style_t *fstyle)
|
||||||
int x, int y, colour c)
|
|
||||||
{
|
{
|
||||||
PangoFontDescription *desc;
|
PangoFontDescription *desc;
|
||||||
PangoLayout *layout;
|
PangoLayout *layout;
|
||||||
@ -229,15 +223,18 @@ bool nsfont_paint(const struct css_style *style,
|
|||||||
#else
|
#else
|
||||||
PangoContext *context;
|
PangoContext *context;
|
||||||
GdkColor colour = { 0,
|
GdkColor colour = { 0,
|
||||||
((c & 0xff) << 8) | (c & 0xff),
|
((fstyle->foreground & 0xff) << 8) |
|
||||||
(c & 0xff00) | (c & 0xff00 >> 8),
|
(fstyle->foreground & 0xff),
|
||||||
((c & 0xff0000) >> 8) | (c & 0xff0000 >> 16) };
|
(fstyle->foreground & 0xff00) |
|
||||||
|
(fstyle->foreground & 0xff00 >> 8),
|
||||||
|
((fstyle->foreground & 0xff0000) >> 8) |
|
||||||
|
(fstyle->foreground & 0xff0000 >> 16) };
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (length == 0)
|
if (length == 0)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
desc = nsfont_style_to_description(style);
|
desc = nsfont_style_to_description(fstyle);
|
||||||
size = (gint)((double)pango_font_description_get_size(desc) * nsgtk_plot_get_scale());
|
size = (gint)((double)pango_font_description_get_size(desc) * nsgtk_plot_get_scale());
|
||||||
if (pango_font_description_get_size_is_absolute(desc))
|
if (pango_font_description_get_size_is_absolute(desc))
|
||||||
pango_font_description_set_absolute_size(desc, size);
|
pango_font_description_set_absolute_size(desc, size);
|
||||||
@ -273,96 +270,60 @@ bool nsfont_paint(const struct css_style *style,
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a css_style to a PangoFontDescription.
|
* Convert a plot style to a PangoFontDescription.
|
||||||
*
|
*
|
||||||
* \param style css_style for this text, with style->font_size.size ==
|
* \param style plot style for this text
|
||||||
* CSS_FONT_SIZE_LENGTH
|
|
||||||
* \return a new Pango font description
|
* \return a new Pango font description
|
||||||
*/
|
*/
|
||||||
|
|
||||||
PangoFontDescription *nsfont_style_to_description(
|
PangoFontDescription *nsfont_style_to_description(
|
||||||
const struct css_style *style)
|
const plot_font_style_t *fstyle)
|
||||||
{
|
{
|
||||||
unsigned int size;
|
unsigned int size;
|
||||||
PangoFontDescription *desc;
|
PangoFontDescription *desc;
|
||||||
PangoWeight weight = PANGO_WEIGHT_NORMAL;
|
PangoStyle style = PANGO_STYLE_NORMAL;
|
||||||
PangoStyle styl = PANGO_STYLE_NORMAL;
|
|
||||||
|
|
||||||
assert(style->font_size.size == CSS_FONT_SIZE_LENGTH);
|
switch (fstyle->family) {
|
||||||
|
case PLOT_FONT_FAMILY_SERIF:
|
||||||
switch (style->font_family) {
|
|
||||||
case CSS_FONT_FAMILY_SERIF:
|
|
||||||
desc = pango_font_description_from_string(option_font_serif);
|
desc = pango_font_description_from_string(option_font_serif);
|
||||||
break;
|
break;
|
||||||
case CSS_FONT_FAMILY_MONOSPACE:
|
case PLOT_FONT_FAMILY_MONOSPACE:
|
||||||
desc = pango_font_description_from_string(option_font_mono);
|
desc = pango_font_description_from_string(option_font_mono);
|
||||||
break;
|
break;
|
||||||
case CSS_FONT_FAMILY_CURSIVE:
|
case PLOT_FONT_FAMILY_CURSIVE:
|
||||||
desc = pango_font_description_from_string(option_font_cursive);
|
desc = pango_font_description_from_string(option_font_cursive);
|
||||||
break;
|
break;
|
||||||
case CSS_FONT_FAMILY_FANTASY:
|
case PLOT_FONT_FAMILY_FANTASY:
|
||||||
desc = pango_font_description_from_string(option_font_fantasy);
|
desc = pango_font_description_from_string(option_font_fantasy);
|
||||||
break;
|
break;
|
||||||
case CSS_FONT_FAMILY_SANS_SERIF:
|
case PLOT_FONT_FAMILY_SANS_SERIF:
|
||||||
default:
|
default:
|
||||||
desc = pango_font_description_from_string(option_font_sans);
|
desc = pango_font_description_from_string(option_font_sans);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size = fstyle->size;
|
||||||
if (style->font_size.value.length.unit == CSS_UNIT_PX)
|
|
||||||
size = style->font_size.value.length.value;
|
|
||||||
else
|
|
||||||
size = css_len2pt(&style->font_size.value.length, style);
|
|
||||||
|
|
||||||
if (size < (unsigned)abs(option_font_min_size / 10))
|
if (size < (unsigned)abs(option_font_min_size / 10))
|
||||||
size = option_font_min_size / 10;
|
size = option_font_min_size / 10;
|
||||||
|
|
||||||
size *= PANGO_SCALE;
|
size *= PANGO_SCALE;
|
||||||
|
|
||||||
switch (style->font_style) {
|
if (fstyle->flags & FONTF_ITALIC)
|
||||||
case CSS_FONT_STYLE_ITALIC:
|
style = PANGO_STYLE_ITALIC;
|
||||||
styl = PANGO_STYLE_ITALIC;
|
else if (fstyle->flags & FONTF_OBLIQUE)
|
||||||
break;
|
style = PANGO_STYLE_OBLIQUE;
|
||||||
case CSS_FONT_STYLE_OBLIQUE:
|
|
||||||
styl = PANGO_STYLE_OBLIQUE;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
pango_font_description_set_style(desc, styl);
|
pango_font_description_set_style(desc, style);
|
||||||
|
|
||||||
switch (style->font_weight) {
|
pango_font_description_set_weight(desc, (PangoWeight) fstyle->weight);
|
||||||
case CSS_FONT_WEIGHT_NORMAL:
|
|
||||||
weight = PANGO_WEIGHT_NORMAL; break;
|
|
||||||
case CSS_FONT_WEIGHT_BOLD:
|
|
||||||
weight = PANGO_WEIGHT_BOLD; break;
|
|
||||||
case CSS_FONT_WEIGHT_100: weight = 100; break;
|
|
||||||
case CSS_FONT_WEIGHT_200: weight = 200; break;
|
|
||||||
case CSS_FONT_WEIGHT_300: weight = 300; break;
|
|
||||||
case CSS_FONT_WEIGHT_400: weight = 400; break;
|
|
||||||
case CSS_FONT_WEIGHT_500: weight = 500; break;
|
|
||||||
case CSS_FONT_WEIGHT_600: weight = 600; break;
|
|
||||||
case CSS_FONT_WEIGHT_700: weight = 700; break;
|
|
||||||
case CSS_FONT_WEIGHT_800: weight = 800; break;
|
|
||||||
case CSS_FONT_WEIGHT_900: weight = 900; break;
|
|
||||||
default: break;
|
|
||||||
}
|
|
||||||
|
|
||||||
pango_font_description_set_weight(desc, weight);
|
pango_font_description_set_size(desc, size);
|
||||||
|
|
||||||
if (style->font_size.value.length.unit == CSS_UNIT_PX)
|
if (fstyle->flags & FONTF_SMALLCAPS) {
|
||||||
pango_font_description_set_absolute_size(desc, size);
|
pango_font_description_set_variant(desc,
|
||||||
else
|
PANGO_VARIANT_SMALL_CAPS);
|
||||||
pango_font_description_set_size(desc, size);
|
} else {
|
||||||
|
|
||||||
switch (style->font_variant) {
|
|
||||||
case CSS_FONT_VARIANT_SMALL_CAPS:
|
|
||||||
pango_font_description_set_variant(desc, PANGO_VARIANT_SMALL_CAPS);
|
|
||||||
break;
|
|
||||||
case CSS_FONT_VARIANT_NORMAL:
|
|
||||||
default:
|
|
||||||
pango_font_description_set_variant(desc, PANGO_VARIANT_NORMAL);
|
pango_font_description_set_variant(desc, PANGO_VARIANT_NORMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,15 +25,13 @@
|
|||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#include "desktop/plot_style.h"
|
||||||
|
|
||||||
struct css_style;
|
bool nsfont_paint(int x, int y, const char *string, size_t length,
|
||||||
|
const plot_font_style_t *fstyle);
|
||||||
bool nsfont_paint(const struct css_style *style,
|
|
||||||
const char *string, size_t length,
|
|
||||||
int x, int y, colour c);
|
|
||||||
|
|
||||||
PangoFontDescription *nsfont_style_to_description(
|
PangoFontDescription *nsfont_style_to_description(
|
||||||
const struct css_style *style);
|
const plot_font_style_t *fstyle);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -304,10 +304,10 @@ static bool nsgtk_plot_polygon(const int *p, unsigned int n, const plot_style_t
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
static bool nsgtk_plot_text(int x, int y, const struct css_style *style,
|
static bool nsgtk_plot_text(int x, int y, const char *text, size_t length,
|
||||||
const char *text, size_t length, colour bg, colour c)
|
const plot_font_style_t *fstyle)
|
||||||
{
|
{
|
||||||
return nsfont_paint(style, text, length, x, y, c);
|
return nsfont_paint(x, y, text, length, fstyle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -107,9 +107,9 @@ static bool nsgtk_print_plot_pixbuf(int x, int y, int width, int height,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool gtk_print_font_paint(const struct css_style *style,
|
static bool gtk_print_font_paint(int x, int y,
|
||||||
const char *string, size_t length,
|
const char *string, size_t length,
|
||||||
int x, int y, colour c)
|
const plot_font_style_t *fstyle)
|
||||||
{
|
{
|
||||||
PangoFontDescription *desc;
|
PangoFontDescription *desc;
|
||||||
PangoLayout *layout;
|
PangoLayout *layout;
|
||||||
@ -119,7 +119,7 @@ static bool gtk_print_font_paint(const struct css_style *style,
|
|||||||
if (length == 0)
|
if (length == 0)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
desc = nsfont_style_to_description(style);
|
desc = nsfont_style_to_description(fstyle);
|
||||||
size = (gint) ((double) pango_font_description_get_size(desc) *
|
size = (gint) ((double) pango_font_description_get_size(desc) *
|
||||||
settings->scale);
|
settings->scale);
|
||||||
|
|
||||||
@ -136,7 +136,7 @@ static bool gtk_print_font_paint(const struct css_style *style,
|
|||||||
line = pango_layout_get_line(layout, 0);
|
line = pango_layout_get_line(layout, 0);
|
||||||
|
|
||||||
cairo_move_to(gtk_print_current_cr, x, y);
|
cairo_move_to(gtk_print_current_cr, x, y);
|
||||||
nsgtk_print_set_colour(c);
|
nsgtk_print_set_colour(fstyle->foreground);
|
||||||
pango_cairo_show_layout_line(gtk_print_current_cr, line);
|
pango_cairo_show_layout_line(gtk_print_current_cr, line);
|
||||||
|
|
||||||
g_object_unref(layout);
|
g_object_unref(layout);
|
||||||
@ -429,10 +429,10 @@ static bool nsgtk_print_plot_bitmap(int x, int y, int width, int height,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool nsgtk_print_plot_text(int x, int y, const struct css_style *style,
|
static bool nsgtk_print_plot_text(int x, int y, const char *text, size_t length,
|
||||||
const char *text, size_t length, colour bg, colour c)
|
const plot_font_style_t *fstyle)
|
||||||
{
|
{
|
||||||
return gtk_print_font_paint(style, text, length, x, y, c);
|
return gtk_print_font_paint(x, y, text, length, fstyle);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** GTK print plotter table */
|
/** GTK print plotter table */
|
||||||
|
@ -98,6 +98,7 @@ bool svg_redraw(struct content *c, int x, int y,
|
|||||||
bool ok;
|
bool ok;
|
||||||
int px, py;
|
int px, py;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
plot_font_style_t fstyle = *plot_style_font;
|
||||||
|
|
||||||
assert(diagram);
|
assert(diagram);
|
||||||
|
|
||||||
@ -128,11 +129,14 @@ bool svg_redraw(struct content *c, int x, int y,
|
|||||||
py = transform[1] * diagram->shape[i].text_x +
|
py = transform[1] * diagram->shape[i].text_x +
|
||||||
transform[3] * diagram->shape[i].text_y +
|
transform[3] * diagram->shape[i].text_y +
|
||||||
transform[5];
|
transform[5];
|
||||||
|
|
||||||
|
fstyle.background = 0xffffff;
|
||||||
|
fstyle.foreground = 0x000000;
|
||||||
|
|
||||||
ok = plot.text(px, py,
|
ok = plot.text(px, py,
|
||||||
&css_base_style,
|
|
||||||
diagram->shape[i].text,
|
diagram->shape[i].text,
|
||||||
strlen(diagram->shape[i].text),
|
strlen(diagram->shape[i].text),
|
||||||
0xffffff, 0x000000);
|
&fstyle);
|
||||||
if (!ok)
|
if (!ok)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
150
render/font.c
Normal file
150
render/font.c
Normal file
@ -0,0 +1,150 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2009 John-Mark Bell <jmb@netsurf-browser.org>
|
||||||
|
*
|
||||||
|
* 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 "css/css.h"
|
||||||
|
#include "render/font.h"
|
||||||
|
|
||||||
|
static plot_font_generic_family_t plot_font_generic_family(
|
||||||
|
css_font_family css);
|
||||||
|
static int plot_font_weight(css_font_weight css);
|
||||||
|
static plot_font_flags_t plot_font_flags(css_font_style style,
|
||||||
|
css_font_variant variant);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Populate a font style using data from a computed CSS style
|
||||||
|
*
|
||||||
|
* \param css Computed style to consider
|
||||||
|
* \param fstyle Font style to populate
|
||||||
|
*/
|
||||||
|
void font_plot_style_from_css(const struct css_style *css,
|
||||||
|
plot_font_style_t *fstyle)
|
||||||
|
{
|
||||||
|
fstyle->family = plot_font_generic_family(css->font_family);
|
||||||
|
fstyle->size = css_len2pt(&css->font_size.value.length, css);
|
||||||
|
fstyle->weight = plot_font_weight(css->font_weight);
|
||||||
|
fstyle->flags = plot_font_flags(css->font_style, css->font_variant);
|
||||||
|
fstyle->foreground = css->color;
|
||||||
|
fstyle->background = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/******************************************************************************
|
||||||
|
* Helper functions *
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Map a generic CSS font family to a generic plot font family
|
||||||
|
*
|
||||||
|
* \param css Generic CSS font family
|
||||||
|
* \return Plot font family
|
||||||
|
*/
|
||||||
|
plot_font_generic_family_t plot_font_generic_family(
|
||||||
|
css_font_family css)
|
||||||
|
{
|
||||||
|
plot_font_generic_family_t plot;
|
||||||
|
|
||||||
|
switch (css) {
|
||||||
|
case CSS_FONT_FAMILY_SERIF:
|
||||||
|
plot = PLOT_FONT_FAMILY_SERIF;
|
||||||
|
break;
|
||||||
|
case CSS_FONT_FAMILY_MONOSPACE:
|
||||||
|
plot = PLOT_FONT_FAMILY_MONOSPACE;
|
||||||
|
break;
|
||||||
|
case CSS_FONT_FAMILY_CURSIVE:
|
||||||
|
plot = PLOT_FONT_FAMILY_CURSIVE;
|
||||||
|
break;
|
||||||
|
case CSS_FONT_FAMILY_FANTASY:
|
||||||
|
plot = PLOT_FONT_FAMILY_FANTASY;
|
||||||
|
break;
|
||||||
|
case CSS_FONT_FAMILY_SANS_SERIF:
|
||||||
|
default:
|
||||||
|
plot = PLOT_FONT_FAMILY_SANS_SERIF;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return plot;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Map a CSS font weight to a plot weight value
|
||||||
|
*
|
||||||
|
* \param css CSS font weight
|
||||||
|
* \return Plot weight
|
||||||
|
*/
|
||||||
|
int plot_font_weight(css_font_weight css)
|
||||||
|
{
|
||||||
|
int weight;
|
||||||
|
|
||||||
|
switch (css) {
|
||||||
|
case CSS_FONT_WEIGHT_100:
|
||||||
|
weight = 100;
|
||||||
|
break;
|
||||||
|
case CSS_FONT_WEIGHT_200:
|
||||||
|
weight = 200;
|
||||||
|
break;
|
||||||
|
case CSS_FONT_WEIGHT_300:
|
||||||
|
weight = 300;
|
||||||
|
break;
|
||||||
|
case CSS_FONT_WEIGHT_400:
|
||||||
|
case CSS_FONT_WEIGHT_NORMAL:
|
||||||
|
default:
|
||||||
|
weight = 400;
|
||||||
|
break;
|
||||||
|
case CSS_FONT_WEIGHT_500:
|
||||||
|
weight = 500;
|
||||||
|
break;
|
||||||
|
case CSS_FONT_WEIGHT_600:
|
||||||
|
weight = 600;
|
||||||
|
break;
|
||||||
|
case CSS_FONT_WEIGHT_700:
|
||||||
|
case CSS_FONT_WEIGHT_BOLD:
|
||||||
|
weight = 700;
|
||||||
|
break;
|
||||||
|
case CSS_FONT_WEIGHT_800:
|
||||||
|
weight = 800;
|
||||||
|
break;
|
||||||
|
case CSS_FONT_WEIGHT_900:
|
||||||
|
weight = 900;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return weight;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Map a CSS font style and font variant to plot font flags
|
||||||
|
*
|
||||||
|
* \param style CSS font style
|
||||||
|
* \param variant CSS font variant
|
||||||
|
* \return Computed plot flags
|
||||||
|
*/
|
||||||
|
plot_font_flags_t plot_font_flags(css_font_style style,
|
||||||
|
css_font_variant variant)
|
||||||
|
{
|
||||||
|
plot_font_flags_t flags = FONTF_NONE;
|
||||||
|
|
||||||
|
if (style == CSS_FONT_STYLE_ITALIC)
|
||||||
|
flags |= FONTF_ITALIC;
|
||||||
|
else if (style == CSS_FONT_STYLE_OBLIQUE)
|
||||||
|
flags |= FONTF_OBLIQUE;
|
||||||
|
|
||||||
|
if (variant == CSS_FONT_VARIANT_SMALL_CAPS)
|
||||||
|
flags |= FONTF_SMALLCAPS;
|
||||||
|
|
||||||
|
return flags;
|
||||||
|
}
|
||||||
|
|
@ -35,23 +35,25 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#include "css/css.h"
|
||||||
struct css_style;
|
#include "desktop/plot_style.h"
|
||||||
|
|
||||||
|
|
||||||
struct font_functions
|
struct font_functions
|
||||||
{
|
{
|
||||||
bool (*font_width)(const struct css_style *style,
|
bool (*font_width)(const plot_font_style_t *fstyle,
|
||||||
const char *string, size_t length,
|
const char *string, size_t length,
|
||||||
int *width);
|
int *width);
|
||||||
bool (*font_position_in_string)(const struct css_style *style,
|
bool (*font_position_in_string)(const plot_font_style_t *fstyle,
|
||||||
const char *string, size_t length,
|
const char *string, size_t length,
|
||||||
int x, size_t *char_offset, int *actual_x);
|
int x, size_t *char_offset, int *actual_x);
|
||||||
bool (*font_split)(const struct css_style *style,
|
bool (*font_split)(const plot_font_style_t *fstyle,
|
||||||
const char *string, size_t length,
|
const char *string, size_t length,
|
||||||
int x, size_t *char_offset, int *actual_x);
|
int x, size_t *char_offset, int *actual_x);
|
||||||
};
|
};
|
||||||
|
|
||||||
extern const struct font_functions nsfont;
|
extern const struct font_functions nsfont;
|
||||||
|
|
||||||
|
void font_plot_style_from_css(const struct css_style *css,
|
||||||
|
plot_font_style_t *fstyle);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include "content/content_type.h"
|
#include "content/content_type.h"
|
||||||
#include "css/css.h"
|
#include "css/css.h"
|
||||||
|
#include "desktop/plot_style.h"
|
||||||
#include "render/parser_binding.h"
|
#include "render/parser_binding.h"
|
||||||
|
|
||||||
struct box;
|
struct box;
|
||||||
@ -197,11 +198,11 @@ bool html_redraw(struct content *c, int x, int y,
|
|||||||
|
|
||||||
bool text_redraw(const char *utf8_text, size_t utf8_len,
|
bool text_redraw(const char *utf8_text, size_t utf8_len,
|
||||||
size_t offset, bool space,
|
size_t offset, bool space,
|
||||||
struct css_style *style,
|
const plot_font_style_t *fstyle,
|
||||||
int x, int y,
|
int x, int y,
|
||||||
struct rect *clip,
|
struct rect *clip,
|
||||||
int height,
|
int height,
|
||||||
float scale, colour current_background_color,
|
float scale,
|
||||||
bool excluded);
|
bool excluded);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -747,6 +747,10 @@ bool html_redraw_text_box(struct box *box, int x, int y,
|
|||||||
{
|
{
|
||||||
bool excluded = (box->object != NULL);
|
bool excluded = (box->object != NULL);
|
||||||
struct rect clip;
|
struct rect clip;
|
||||||
|
plot_font_style_t fstyle;
|
||||||
|
|
||||||
|
font_plot_style_from_css(box->style, &fstyle);
|
||||||
|
fstyle.background = current_background_color;
|
||||||
|
|
||||||
clip.x0 = x0;
|
clip.x0 = x0;
|
||||||
clip.y0 = y0;
|
clip.y0 = y0;
|
||||||
@ -754,9 +758,8 @@ bool html_redraw_text_box(struct box *box, int x, int y,
|
|||||||
clip.y1 = y1;
|
clip.y1 = y1;
|
||||||
|
|
||||||
if (!text_redraw(box->text, box->length, box->byte_offset,
|
if (!text_redraw(box->text, box->length, box->byte_offset,
|
||||||
box->space, box->style, x, y,
|
box->space, &fstyle, x, y,
|
||||||
&clip, box->height, scale,
|
&clip, box->height, scale, excluded))
|
||||||
current_background_color, excluded))
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
/* does this textbox contain the ghost caret? */
|
/* does this textbox contain the ghost caret? */
|
||||||
@ -769,7 +772,6 @@ bool html_redraw_text_box(struct box *box, int x, int y,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Redraw a short text string, complete with highlighting
|
* Redraw a short text string, complete with highlighting
|
||||||
* (for selection/search) and ghost caret
|
* (for selection/search) and ghost caret
|
||||||
@ -778,22 +780,21 @@ bool html_redraw_text_box(struct box *box, int x, int y,
|
|||||||
* \param utf8_len length of string, in bytes
|
* \param utf8_len length of string, in bytes
|
||||||
* \param offset byte offset within textual representation
|
* \param offset byte offset within textual representation
|
||||||
* \param space indicates whether string is followed by a space
|
* \param space indicates whether string is followed by a space
|
||||||
* \param style text style to use
|
* \param fstyle text style to use
|
||||||
* \param x x ordinate at which to plot text
|
* \param x x ordinate at which to plot text
|
||||||
* \param y y ordinate at which to plot text
|
* \param y y ordinate at which to plot text
|
||||||
* \param clip pointer to current clip rectangle
|
* \param clip pointer to current clip rectangle
|
||||||
* \param height height of text string
|
* \param height height of text string
|
||||||
* \param scale current display scale (1.0 = 100%)
|
* \param scale current display scale (1.0 = 100%)
|
||||||
* \param current_background_color
|
|
||||||
* \param excluded exclude this text string from the selection
|
* \param excluded exclude this text string from the selection
|
||||||
* \return true iff successful and redraw should proceed
|
* \return true iff successful and redraw should proceed
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool text_redraw(const char *utf8_text, size_t utf8_len,
|
bool text_redraw(const char *utf8_text, size_t utf8_len,
|
||||||
size_t offset, bool space, struct css_style *style,
|
size_t offset, bool space, const plot_font_style_t *fstyle,
|
||||||
int x, int y, struct rect *clip,
|
int x, int y, struct rect *clip,
|
||||||
int height,
|
int height,
|
||||||
float scale, colour current_background_color,
|
float scale,
|
||||||
bool excluded)
|
bool excluded)
|
||||||
{
|
{
|
||||||
bool highlighted = false;
|
bool highlighted = false;
|
||||||
@ -828,6 +829,7 @@ bool text_redraw(const char *utf8_text, size_t utf8_len,
|
|||||||
bool text_visible = true;
|
bool text_visible = true;
|
||||||
int startx, endx;
|
int startx, endx;
|
||||||
plot_style_t *pstyle_fill_hback = plot_style_fill_white;
|
plot_style_t *pstyle_fill_hback = plot_style_fill_white;
|
||||||
|
plot_font_style_t fstyle_hback = *fstyle;
|
||||||
|
|
||||||
if (end_idx > utf8_len) {
|
if (end_idx > utf8_len) {
|
||||||
/* adjust for trailing space, not present in
|
/* adjust for trailing space, not present in
|
||||||
@ -836,11 +838,11 @@ bool text_redraw(const char *utf8_text, size_t utf8_len,
|
|||||||
endtxt_idx = utf8_len;
|
endtxt_idx = utf8_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!nsfont.font_width(style, utf8_text, start_idx,
|
if (!nsfont.font_width(fstyle, utf8_text, start_idx,
|
||||||
&startx))
|
&startx))
|
||||||
startx = 0;
|
startx = 0;
|
||||||
|
|
||||||
if (!nsfont.font_width(style, utf8_text, endtxt_idx,
|
if (!nsfont.font_width(fstyle, utf8_text, endtxt_idx,
|
||||||
&endx))
|
&endx))
|
||||||
endx = 0;
|
endx = 0;
|
||||||
|
|
||||||
@ -850,7 +852,7 @@ bool text_redraw(const char *utf8_text, size_t utf8_len,
|
|||||||
int spc_width;
|
int spc_width;
|
||||||
/* \todo is there a more elegant/efficient
|
/* \todo is there a more elegant/efficient
|
||||||
* solution? */
|
* solution? */
|
||||||
if (nsfont.font_width(style, " ", 1,
|
if (nsfont.font_width(fstyle, " ", 1,
|
||||||
&spc_width))
|
&spc_width))
|
||||||
endx += spc_width;
|
endx += spc_width;
|
||||||
}
|
}
|
||||||
@ -863,15 +865,13 @@ bool text_redraw(const char *utf8_text, size_t utf8_len,
|
|||||||
/* draw any text preceding highlighted portion */
|
/* draw any text preceding highlighted portion */
|
||||||
if (start_idx > 0 &&
|
if (start_idx > 0 &&
|
||||||
!plot.text(x, y + (int) (height * 0.75 * scale),
|
!plot.text(x, y + (int) (height * 0.75 * scale),
|
||||||
style, utf8_text, start_idx,
|
utf8_text, start_idx,
|
||||||
current_background_color,
|
fstyle))
|
||||||
/*print_text_black ? 0 :*/
|
|
||||||
style->color))
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
/* decide whether highlighted portion is to be
|
/* decide whether highlighted portion is to be
|
||||||
* white-on-black or black-on-white */
|
* white-on-black or black-on-white */
|
||||||
if ((current_background_color & 0x808080) == 0x808080)
|
if ((fstyle->background & 0x808080) == 0x808080)
|
||||||
pstyle_fill_hback = plot_style_fill_black;
|
pstyle_fill_hback = plot_style_fill_black;
|
||||||
|
|
||||||
/* highlighted portion */
|
/* highlighted portion */
|
||||||
@ -894,11 +894,15 @@ bool text_redraw(const char *utf8_text, size_t utf8_len,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fstyle_hback.background =
|
||||||
|
pstyle_fill_hback->fill_colour ^ 0xffffff;
|
||||||
|
fstyle_hback.foreground =
|
||||||
|
pstyle_fill_hback->fill_colour;
|
||||||
|
|
||||||
if (text_visible &&
|
if (text_visible &&
|
||||||
!plot.text(x, y + (int) (height * 0.75 * scale),
|
!plot.text(x, y + (int) (height * 0.75 * scale),
|
||||||
style, utf8_text, endtxt_idx,
|
utf8_text, endtxt_idx,
|
||||||
pstyle_fill_hback->fill_colour,
|
&fstyle_hback))
|
||||||
pstyle_fill_hback->fill_colour ^ 0xffffff))
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
/* draw any text succeeding highlighted portion */
|
/* draw any text succeeding highlighted portion */
|
||||||
@ -914,10 +918,8 @@ bool text_redraw(const char *utf8_text, size_t utf8_len,
|
|||||||
|
|
||||||
if (!plot.text(x, y + (int)
|
if (!plot.text(x, y + (int)
|
||||||
(height * 0.75 * scale),
|
(height * 0.75 * scale),
|
||||||
style, utf8_text, utf8_len,
|
utf8_text, utf8_len,
|
||||||
current_background_color,
|
fstyle))
|
||||||
/*print_text_black ? 0 :*/
|
|
||||||
style->color))
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -931,9 +933,8 @@ bool text_redraw(const char *utf8_text, size_t utf8_len,
|
|||||||
|
|
||||||
if (!highlighted) {
|
if (!highlighted) {
|
||||||
if (!plot.text(x, y + (int) (height * 0.75 * scale),
|
if (!plot.text(x, y + (int) (height * 0.75 * scale),
|
||||||
style, utf8_text, utf8_len,
|
utf8_text, utf8_len,
|
||||||
current_background_color,
|
fstyle))
|
||||||
/*print_text_black ? 0 :*/ style->color))
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -1396,6 +1397,10 @@ bool html_redraw_file(int x, int y, int width, int height,
|
|||||||
int text_width;
|
int text_width;
|
||||||
const char *text;
|
const char *text;
|
||||||
size_t length;
|
size_t length;
|
||||||
|
plot_font_style_t fstyle;
|
||||||
|
|
||||||
|
font_plot_style_from_css(box->style, &fstyle);
|
||||||
|
fstyle.background = background_colour;
|
||||||
|
|
||||||
if (box->gadget->value)
|
if (box->gadget->value)
|
||||||
text = box->gadget->value;
|
text = box->gadget->value;
|
||||||
@ -1403,7 +1408,7 @@ bool html_redraw_file(int x, int y, int width, int height,
|
|||||||
text = messages_get("Form_Drop");
|
text = messages_get("Form_Drop");
|
||||||
length = strlen(text);
|
length = strlen(text);
|
||||||
|
|
||||||
if (!nsfont.font_width(box->style, text, length, &text_width))
|
if (!nsfont.font_width(&fstyle, text, length, &text_width))
|
||||||
return false;
|
return false;
|
||||||
text_width *= scale;
|
text_width *= scale;
|
||||||
if (width < text_width + 8)
|
if (width < text_width + 8)
|
||||||
@ -1411,9 +1416,7 @@ bool html_redraw_file(int x, int y, int width, int height,
|
|||||||
else
|
else
|
||||||
x = x + 4;
|
x = x + 4;
|
||||||
|
|
||||||
return plot.text(x, y + height * 0.75, box->style, text, length,
|
return plot.text(x, y + height * 0.75, text, length, &fstyle);
|
||||||
background_colour,
|
|
||||||
/*print_text_black ? 0 :*/ box->style->color);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1668,6 +1668,7 @@ bool layout_line(struct box *first, int *width, int *y,
|
|||||||
unsigned int i;
|
unsigned int i;
|
||||||
struct css_length gadget_size; /* Checkbox / radio buttons */
|
struct css_length gadget_size; /* Checkbox / radio buttons */
|
||||||
const struct font_functions *font_func = content->data.html.font_func;
|
const struct font_functions *font_func = content->data.html.font_func;
|
||||||
|
plot_font_style_t fstyle;
|
||||||
|
|
||||||
gadget_size.unit = CSS_UNIT_EM;
|
gadget_size.unit = CSS_UNIT_EM;
|
||||||
gadget_size.value = 1;
|
gadget_size.value = 1;
|
||||||
@ -1722,6 +1723,9 @@ bool layout_line(struct box *first, int *width, int *y,
|
|||||||
b->style->position == CSS_POSITION_FIXED))
|
b->style->position == CSS_POSITION_FIXED))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
assert(b->style != NULL);
|
||||||
|
font_plot_style_from_css(b->style, &fstyle);
|
||||||
|
|
||||||
x += space_after;
|
x += space_after;
|
||||||
|
|
||||||
if (b->type == BOX_INLINE_BLOCK) {
|
if (b->type == BOX_INLINE_BLOCK) {
|
||||||
@ -1763,7 +1767,7 @@ bool layout_line(struct box *first, int *width, int *y,
|
|||||||
b->width = 0;
|
b->width = 0;
|
||||||
if (b->space) {
|
if (b->space) {
|
||||||
/** \todo optimize out */
|
/** \todo optimize out */
|
||||||
font_func->font_width(b->style, " ", 1,
|
font_func->font_width(&fstyle, " ", 1,
|
||||||
&space_after);
|
&space_after);
|
||||||
} else {
|
} else {
|
||||||
space_after = 0;
|
space_after = 0;
|
||||||
@ -1801,7 +1805,7 @@ bool layout_line(struct box *first, int *width, int *y,
|
|||||||
data.select.items; o;
|
data.select.items; o;
|
||||||
o = o->next) {
|
o = o->next) {
|
||||||
int opt_width;
|
int opt_width;
|
||||||
font_func->font_width(b->style,
|
font_func->font_width(&fstyle,
|
||||||
o->text,
|
o->text,
|
||||||
strlen(o->text),
|
strlen(o->text),
|
||||||
&opt_width);
|
&opt_width);
|
||||||
@ -1812,7 +1816,7 @@ bool layout_line(struct box *first, int *width, int *y,
|
|||||||
|
|
||||||
b->width = opt_maxwidth;
|
b->width = opt_maxwidth;
|
||||||
} else {
|
} else {
|
||||||
font_func->font_width(b->style, b->text,
|
font_func->font_width(&fstyle, b->text,
|
||||||
b->length, &b->width);
|
b->length, &b->width);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1820,7 +1824,7 @@ bool layout_line(struct box *first, int *width, int *y,
|
|||||||
x += b->width;
|
x += b->width;
|
||||||
if (b->space)
|
if (b->space)
|
||||||
/** \todo optimize out */
|
/** \todo optimize out */
|
||||||
font_func->font_width(b->style, " ", 1,
|
font_func->font_width(&fstyle, " ", 1,
|
||||||
&space_after);
|
&space_after);
|
||||||
else
|
else
|
||||||
space_after = 0;
|
space_after = 0;
|
||||||
@ -1957,10 +1961,13 @@ bool layout_line(struct box *first, int *width, int *y,
|
|||||||
space_after = 0;
|
space_after = 0;
|
||||||
else if (b->text || b->type == BOX_INLINE_END) {
|
else if (b->text || b->type == BOX_INLINE_END) {
|
||||||
space_after = 0;
|
space_after = 0;
|
||||||
if (b->space)
|
if (b->space) {
|
||||||
|
font_plot_style_from_css(b->style,
|
||||||
|
&fstyle);
|
||||||
/** \todo handle errors, optimize */
|
/** \todo handle errors, optimize */
|
||||||
font_func->font_width(b->style, " ", 1,
|
font_func->font_width(&fstyle, " ", 1,
|
||||||
&space_after);
|
&space_after);
|
||||||
|
}
|
||||||
} else
|
} else
|
||||||
space_after = 0;
|
space_after = 0;
|
||||||
split_box = b;
|
split_box = b;
|
||||||
@ -2099,10 +2106,12 @@ bool layout_line(struct box *first, int *width, int *y,
|
|||||||
|
|
||||||
if (space == 0)
|
if (space == 0)
|
||||||
w = split_box->width;
|
w = split_box->width;
|
||||||
else
|
else {
|
||||||
|
font_plot_style_from_css(split_box->style, &fstyle);
|
||||||
/** \todo handle errors */
|
/** \todo handle errors */
|
||||||
font_func->font_width(split_box->style, split_box->text,
|
font_func->font_width(&fstyle, split_box->text,
|
||||||
space, &w);
|
space, &w);
|
||||||
|
}
|
||||||
|
|
||||||
LOG(("splitting: split_box %p \"%.*s\", space %zu, w %i, "
|
LOG(("splitting: split_box %p \"%.*s\", space %zu, w %i, "
|
||||||
"left %p, right %p, inline_count %u",
|
"left %p, right %p, inline_count %u",
|
||||||
@ -2171,8 +2180,9 @@ bool layout_line(struct box *first, int *width, int *y,
|
|||||||
} else {
|
} else {
|
||||||
/* fit as many words as possible */
|
/* fit as many words as possible */
|
||||||
assert(space != 0);
|
assert(space != 0);
|
||||||
|
font_plot_style_from_css(split_box->style, &fstyle);
|
||||||
/** \todo handle errors */
|
/** \todo handle errors */
|
||||||
font_func->font_split(split_box->style,
|
font_func->font_split(&fstyle,
|
||||||
split_box->text, split_box->length,
|
split_box->text, split_box->length,
|
||||||
x1 - x0 - x - space_before, &space, &w);
|
x1 - x0 - x - space_before, &space, &w);
|
||||||
LOG(("'%.*s' %i %zu %i", (int) split_box->length,
|
LOG(("'%.*s' %i %zu %i", (int) split_box->length,
|
||||||
@ -2294,6 +2304,8 @@ struct box *layout_minmax_line(struct box *first,
|
|||||||
size_t i, j;
|
size_t i, j;
|
||||||
struct box *b;
|
struct box *b;
|
||||||
struct css_length gadget_size; /* Checkbox / radio buttons */
|
struct css_length gadget_size; /* Checkbox / radio buttons */
|
||||||
|
plot_font_style_t fstyle;
|
||||||
|
|
||||||
gadget_size.unit = CSS_UNIT_EM;
|
gadget_size.unit = CSS_UNIT_EM;
|
||||||
gadget_size.value = 1;
|
gadget_size.value = 1;
|
||||||
|
|
||||||
@ -2334,6 +2346,9 @@ struct box *layout_minmax_line(struct box *first,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert(b->style);
|
||||||
|
font_plot_style_from_css(b->style, &fstyle);
|
||||||
|
|
||||||
if (b->type == BOX_INLINE && !b->object) {
|
if (b->type == BOX_INLINE && !b->object) {
|
||||||
fixed = frac = 0;
|
fixed = frac = 0;
|
||||||
calculate_mbp_width(b->style, LEFT, true, true, true,
|
calculate_mbp_width(b->style, LEFT, true, true, true,
|
||||||
@ -2353,7 +2368,7 @@ struct box *layout_minmax_line(struct box *first,
|
|||||||
if (0 < fixed)
|
if (0 < fixed)
|
||||||
max += fixed;
|
max += fixed;
|
||||||
if (b->next && b->space) {
|
if (b->next && b->space) {
|
||||||
font_func->font_width(b->style, " ", 1, &width);
|
font_func->font_width(&fstyle, " ", 1, &width);
|
||||||
max += width;
|
max += width;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
@ -2379,7 +2394,7 @@ struct box *layout_minmax_line(struct box *first,
|
|||||||
data.select.items; o;
|
data.select.items; o;
|
||||||
o = o->next) {
|
o = o->next) {
|
||||||
int opt_width;
|
int opt_width;
|
||||||
font_func->font_width(b->style,
|
font_func->font_width(&fstyle,
|
||||||
o->text,
|
o->text,
|
||||||
strlen(o->text),
|
strlen(o->text),
|
||||||
&opt_width);
|
&opt_width);
|
||||||
@ -2390,13 +2405,13 @@ struct box *layout_minmax_line(struct box *first,
|
|||||||
|
|
||||||
b->width = opt_maxwidth;
|
b->width = opt_maxwidth;
|
||||||
} else {
|
} else {
|
||||||
font_func->font_width(b->style, b->text,
|
font_func->font_width(&fstyle, b->text,
|
||||||
b->length, &b->width);
|
b->length, &b->width);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
max += b->width;
|
max += b->width;
|
||||||
if (b->next && b->space) {
|
if (b->next && b->space) {
|
||||||
font_func->font_width(b->style, " ", 1, &width);
|
font_func->font_width(&fstyle, " ", 1, &width);
|
||||||
max += width;
|
max += width;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2406,7 +2421,7 @@ struct box *layout_minmax_line(struct box *first,
|
|||||||
for (j = i; j != b->length &&
|
for (j = i; j != b->length &&
|
||||||
b->text[j] != ' '; j++)
|
b->text[j] != ' '; j++)
|
||||||
;
|
;
|
||||||
font_func->font_width(b->style, b->text + i,
|
font_func->font_width(&fstyle, b->text + i,
|
||||||
j - i, &width);
|
j - i, &width);
|
||||||
if (min < width)
|
if (min < width)
|
||||||
min = width;
|
min = width;
|
||||||
@ -3327,6 +3342,7 @@ void layout_lists(struct box *box,
|
|||||||
{
|
{
|
||||||
struct box *child;
|
struct box *child;
|
||||||
struct box *marker;
|
struct box *marker;
|
||||||
|
plot_font_style_t fstyle;
|
||||||
|
|
||||||
for (child = box->children; child; child = child->next) {
|
for (child = box->children; child; child = child->next) {
|
||||||
if (child->list_marker) {
|
if (child->list_marker) {
|
||||||
@ -3338,11 +3354,14 @@ void layout_lists(struct box *box,
|
|||||||
marker->y = (line_height(marker->style) -
|
marker->y = (line_height(marker->style) -
|
||||||
marker->height) / 2;
|
marker->height) / 2;
|
||||||
} else if (marker->text) {
|
} else if (marker->text) {
|
||||||
if (marker->width == UNKNOWN_WIDTH)
|
if (marker->width == UNKNOWN_WIDTH) {
|
||||||
font_func->font_width(marker->style,
|
font_plot_style_from_css(marker->style,
|
||||||
|
&fstyle);
|
||||||
|
font_func->font_width(&fstyle,
|
||||||
marker->text,
|
marker->text,
|
||||||
marker->length,
|
marker->length,
|
||||||
&marker->width);
|
&marker->width);
|
||||||
|
}
|
||||||
marker->x = -marker->width;
|
marker->x = -marker->width;
|
||||||
marker->y = 0;
|
marker->y = 0;
|
||||||
marker->height = line_height(marker->style);
|
marker->height = line_height(marker->style);
|
||||||
|
@ -115,6 +115,10 @@ bool loosen_text(struct box *text, int width, struct content *content)
|
|||||||
unsigned int position;
|
unsigned int position;
|
||||||
const struct font_functions *font_func;
|
const struct font_functions *font_func;
|
||||||
|
|
||||||
|
plot_font_style_t fstyle;
|
||||||
|
|
||||||
|
font_plot_style_from_css(text->style, &fstyle);
|
||||||
|
|
||||||
if (content->type == CONTENT_HTML)
|
if (content->type == CONTENT_HTML)
|
||||||
font_func = content->data.html.font_func;
|
font_func = content->data.html.font_func;
|
||||||
else
|
else
|
||||||
@ -134,7 +138,7 @@ bool loosen_text(struct box *text, int width, struct content *content)
|
|||||||
position = 0;
|
position = 0;
|
||||||
|
|
||||||
while (position < text->length) {
|
while (position < text->length) {
|
||||||
font_func->font_position_in_string(text->style,
|
font_func->font_position_in_string(&fstyle,
|
||||||
text->text + position,
|
text->text + position,
|
||||||
text->length - position,
|
text->length - position,
|
||||||
width, &offset, &actual_x);
|
width, &offset, &actual_x);
|
||||||
|
@ -49,11 +49,20 @@
|
|||||||
|
|
||||||
#define TAB_WIDTH 8 /* must be power of 2 currently */
|
#define TAB_WIDTH 8 /* must be power of 2 currently */
|
||||||
|
|
||||||
static struct css_style textplain_style;
|
static plot_font_style_t textplain_style = {
|
||||||
|
.family = PLOT_FONT_FAMILY_MONOSPACE,
|
||||||
|
.size = 10,
|
||||||
|
.weight = 400,
|
||||||
|
.flags = FONTF_NONE,
|
||||||
|
.background = 0xffffff,
|
||||||
|
.foreground = 0x000000,
|
||||||
|
};
|
||||||
|
|
||||||
static int textplain_tab_width = 256; /* try for a sensible default */
|
static int textplain_tab_width = 256; /* try for a sensible default */
|
||||||
|
|
||||||
static int textplain_coord_from_offset(const char *text, size_t offset,
|
static int textplain_coord_from_offset(const char *text, size_t offset,
|
||||||
size_t length);
|
size_t length);
|
||||||
|
static float textplain_line_height(void);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -68,9 +77,6 @@ bool textplain_create(struct content *c, const char *params[])
|
|||||||
iconv_t iconv_cd;
|
iconv_t iconv_cd;
|
||||||
union content_msg_data msg_data;
|
union content_msg_data msg_data;
|
||||||
|
|
||||||
textplain_style = css_base_style;
|
|
||||||
textplain_style.font_family = CSS_FONT_FAMILY_MONOSPACE;
|
|
||||||
|
|
||||||
utf8_data = talloc_array(c, char, CHUNK);
|
utf8_data = talloc_array(c, char, CHUNK);
|
||||||
if (!utf8_data)
|
if (!utf8_data)
|
||||||
goto no_memory;
|
goto no_memory;
|
||||||
@ -281,9 +287,7 @@ void textplain_reformat(struct content *c, int width, int height)
|
|||||||
|
|
||||||
c->data.textplain.physical_line_count = line_count;
|
c->data.textplain.physical_line_count = line_count;
|
||||||
c->width = width;
|
c->width = width;
|
||||||
c->height = line_count *
|
c->height = line_count * textplain_line_height() + MARGIN + MARGIN;
|
||||||
css_len2px(&textplain_style.font_size.value.length,
|
|
||||||
&textplain_style) * 1.2 + MARGIN + MARGIN;
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -332,8 +336,7 @@ bool textplain_redraw(struct content *c, int x, int y,
|
|||||||
char *utf8_data = c->data.textplain.utf8_data;
|
char *utf8_data = c->data.textplain.utf8_data;
|
||||||
long lineno;
|
long lineno;
|
||||||
unsigned long line_count = c->data.textplain.physical_line_count;
|
unsigned long line_count = c->data.textplain.physical_line_count;
|
||||||
float line_height = css_len2px(&textplain_style.font_size.value.length,
|
float line_height = textplain_line_height();
|
||||||
&textplain_style) * 1.2;
|
|
||||||
float scaled_line_height = line_height * scale;
|
float scaled_line_height = line_height * scale;
|
||||||
long line0 = clip_y0 / scaled_line_height - 1;
|
long line0 = clip_y0 / scaled_line_height - 1;
|
||||||
long line1 = clip_y1 / scaled_line_height + 1;
|
long line1 = clip_y1 / scaled_line_height + 1;
|
||||||
@ -370,6 +373,9 @@ bool textplain_redraw(struct content *c, int x, int y,
|
|||||||
else
|
else
|
||||||
plot_style_highlight = plot_style_fill_white;
|
plot_style_highlight = plot_style_fill_white;
|
||||||
|
|
||||||
|
/* Set background colour to plot with */
|
||||||
|
textplain_style.background = background_colour;
|
||||||
|
|
||||||
x += MARGIN * scale;
|
x += MARGIN * scale;
|
||||||
y += MARGIN * scale;
|
y += MARGIN * scale;
|
||||||
for (lineno = line0; lineno != line1; lineno++) {
|
for (lineno = line0; lineno != line1; lineno++) {
|
||||||
@ -396,8 +402,7 @@ bool textplain_redraw(struct content *c, int x, int y,
|
|||||||
line[lineno].start + offset, false,
|
line[lineno].start + offset, false,
|
||||||
&textplain_style,
|
&textplain_style,
|
||||||
tx, y + (lineno * scaled_line_height),
|
tx, y + (lineno * scaled_line_height),
|
||||||
&clip, line_height, scale,
|
&clip, line_height, scale, false))
|
||||||
background_colour, false))
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (next_offset >= length)
|
if (next_offset >= length)
|
||||||
@ -468,8 +473,7 @@ bool textplain_redraw(struct content *c, int x, int y,
|
|||||||
|
|
||||||
size_t textplain_offset_from_coords(struct content *c, int x, int y, int dir)
|
size_t textplain_offset_from_coords(struct content *c, int x, int y, int dir)
|
||||||
{
|
{
|
||||||
float line_height = css_len2px(&textplain_style.font_size.value.length,
|
float line_height = textplain_line_height();
|
||||||
&textplain_style) * 1.2;
|
|
||||||
struct textplain_line *line;
|
struct textplain_line *line;
|
||||||
const char *text;
|
const char *text;
|
||||||
unsigned nlines;
|
unsigned nlines;
|
||||||
@ -618,8 +622,7 @@ int textplain_coord_from_offset(const char *text, size_t offset, size_t length)
|
|||||||
void textplain_coords_from_range(struct content *c, unsigned start, unsigned end,
|
void textplain_coords_from_range(struct content *c, unsigned start, unsigned end,
|
||||||
struct rect *r)
|
struct rect *r)
|
||||||
{
|
{
|
||||||
float line_height = css_len2px(&textplain_style.font_size.value.length,
|
float line_height = textplain_line_height();
|
||||||
&textplain_style) * 1.2;
|
|
||||||
char *utf8_data = c->data.textplain.utf8_data;
|
char *utf8_data = c->data.textplain.utf8_data;
|
||||||
struct textplain_line *line;
|
struct textplain_line *line;
|
||||||
unsigned lineno = 0;
|
unsigned lineno = 0;
|
||||||
@ -719,3 +722,17 @@ char *textplain_get_raw_data(struct content *c, unsigned start, unsigned end,
|
|||||||
|
|
||||||
return c->data.textplain.utf8_data + start;
|
return c->data.textplain.utf8_data + start;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculate the line height, in pixels
|
||||||
|
*
|
||||||
|
* \return Line height, in pixels
|
||||||
|
*/
|
||||||
|
float textplain_line_height(void)
|
||||||
|
{
|
||||||
|
/* Size is in points, so convert to pixels.
|
||||||
|
* Then use a constant line height of 1.2 x font size.
|
||||||
|
*/
|
||||||
|
return (textplain_style.size * css_screen_dpi / 72) * 1.2;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include "css/css.h"
|
#include "css/css.h"
|
||||||
#include "desktop/options.h"
|
#include "desktop/options.h"
|
||||||
|
#include "desktop/plot_style.h"
|
||||||
#include "riscos/dialog.h"
|
#include "riscos/dialog.h"
|
||||||
#include "riscos/gui.h"
|
#include "riscos/gui.h"
|
||||||
#include "riscos/menus.h"
|
#include "riscos/menus.h"
|
||||||
@ -58,6 +59,14 @@
|
|||||||
* probably be released at some point */
|
* probably be released at some point */
|
||||||
static wimp_menu *default_menu;
|
static wimp_menu *default_menu;
|
||||||
|
|
||||||
|
static const char *font_names[PLOT_FONT_FAMILY_COUNT] = {
|
||||||
|
"Sans-serif",
|
||||||
|
"Serif",
|
||||||
|
"Monospace",
|
||||||
|
"Cursive",
|
||||||
|
"Fantasy"
|
||||||
|
};
|
||||||
|
|
||||||
static void ro_gui_options_fonts_default(wimp_pointer *pointer);
|
static void ro_gui_options_fonts_default(wimp_pointer *pointer);
|
||||||
static bool ro_gui_options_fonts_ok(wimp_w w);
|
static bool ro_gui_options_fonts_ok(wimp_w w);
|
||||||
static bool ro_gui_options_fonts_init_menu(void);
|
static bool ro_gui_options_fonts_init_menu(void);
|
||||||
@ -73,7 +82,7 @@ bool ro_gui_options_fonts_initialise(wimp_w w)
|
|||||||
ro_gui_set_icon_string(w, FONT_CURSIVE_FIELD, option_font_cursive, true);
|
ro_gui_set_icon_string(w, FONT_CURSIVE_FIELD, option_font_cursive, true);
|
||||||
ro_gui_set_icon_string(w, FONT_FANTASY_FIELD, option_font_fantasy, true);
|
ro_gui_set_icon_string(w, FONT_FANTASY_FIELD, option_font_fantasy, true);
|
||||||
ro_gui_set_icon_string(w, FONT_DEFAULT_FIELD,
|
ro_gui_set_icon_string(w, FONT_DEFAULT_FIELD,
|
||||||
css_font_family_name[option_font_default], true);
|
font_names[option_font_default], true);
|
||||||
|
|
||||||
if (!ro_gui_options_fonts_init_menu())
|
if (!ro_gui_options_fonts_init_menu())
|
||||||
return false;
|
return false;
|
||||||
@ -124,7 +133,7 @@ void ro_gui_options_fonts_default(wimp_pointer *pointer)
|
|||||||
ro_gui_set_icon_string(pointer->w, FONT_FANTASY_FIELD,
|
ro_gui_set_icon_string(pointer->w, FONT_FANTASY_FIELD,
|
||||||
nsfont_exists("Sassoon") ? "Sassoon" : fallback, true);
|
nsfont_exists("Sassoon") ? "Sassoon" : fallback, true);
|
||||||
ro_gui_set_icon_string(pointer->w, FONT_DEFAULT_FIELD,
|
ro_gui_set_icon_string(pointer->w, FONT_DEFAULT_FIELD,
|
||||||
css_font_family_name[1], true);
|
font_names[0], true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ro_gui_options_fonts_ok(wimp_w w)
|
bool ro_gui_options_fonts_ok(wimp_w w)
|
||||||
@ -149,16 +158,15 @@ bool ro_gui_options_fonts_ok(wimp_w w)
|
|||||||
option_font_fantasy = strdup(ro_gui_get_icon_string(w, FONT_FANTASY_FIELD));
|
option_font_fantasy = strdup(ro_gui_get_icon_string(w, FONT_FANTASY_FIELD));
|
||||||
|
|
||||||
for (i = 0; i != 5; i++) {
|
for (i = 0; i != 5; i++) {
|
||||||
if (!strcmp(css_font_family_name[i+1],
|
if (!strcmp(font_names[i], ro_gui_get_icon_string(w,
|
||||||
ro_gui_get_icon_string(w,
|
FONT_DEFAULT_FIELD)))
|
||||||
FONT_DEFAULT_FIELD)))
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (i == 5)
|
if (i == 5)
|
||||||
/* this should never happen, but still */
|
/* this should never happen, but still */
|
||||||
i = 0;
|
i = 0;
|
||||||
|
|
||||||
option_font_default = i + 1;
|
option_font_default = i;
|
||||||
|
|
||||||
ro_gui_save_options();
|
ro_gui_save_options();
|
||||||
return true;
|
return true;
|
||||||
@ -182,9 +190,9 @@ bool ro_gui_options_fonts_init_menu(void)
|
|||||||
ro_gui_menu_init_structure(default_menu, 5);
|
ro_gui_menu_init_structure(default_menu, 5);
|
||||||
for (i = 0; i < 5; i++) {
|
for (i = 0; i < 5; i++) {
|
||||||
default_menu->entries[i].data.indirected_text.text =
|
default_menu->entries[i].data.indirected_text.text =
|
||||||
(char *) css_font_family_name[i+1];
|
(char *) font_names[i];
|
||||||
default_menu->entries[i].data.indirected_text.size =
|
default_menu->entries[i].data.indirected_text.size =
|
||||||
strlen(css_font_family_name[i+1]);
|
strlen(font_names[i]);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
125
riscos/font.c
125
riscos/font.c
@ -41,13 +41,13 @@ static int nsfont_list_cmp(const void *keyval, const void *datum);
|
|||||||
static void nsfont_check_fonts(void);
|
static void nsfont_check_fonts(void);
|
||||||
static void ro_gui_wimp_desktop_font(char *family, size_t bufsize, int *psize,
|
static void ro_gui_wimp_desktop_font(char *family, size_t bufsize, int *psize,
|
||||||
rufl_style *pstyle);
|
rufl_style *pstyle);
|
||||||
static bool nsfont_width(const struct css_style *style,
|
static bool nsfont_width(const plot_font_style_t *fstyle,
|
||||||
const char *string, size_t length,
|
const char *string, size_t length,
|
||||||
int *width);
|
int *width);
|
||||||
static bool nsfont_position_in_string(const struct css_style *style,
|
static bool nsfont_position_in_string(const plot_font_style_t *fstyle,
|
||||||
const char *string, size_t length,
|
const char *string, size_t length,
|
||||||
int x, size_t *char_offset, int *actual_x);
|
int x, size_t *char_offset, int *actual_x);
|
||||||
static bool nsfont_split(const struct css_style *style,
|
static bool nsfont_split(const plot_font_style_t *fstyle,
|
||||||
const char *string, size_t length,
|
const char *string, size_t length,
|
||||||
int x, size_t *char_offset, int *actual_x);
|
int x, size_t *char_offset, int *actual_x);
|
||||||
|
|
||||||
@ -99,12 +99,12 @@ void nsfont_init(void)
|
|||||||
nsfont_check_option(&option_font_cursive, "Churchill", fallback);
|
nsfont_check_option(&option_font_cursive, "Churchill", fallback);
|
||||||
nsfont_check_option(&option_font_fantasy, "Sassoon", fallback);
|
nsfont_check_option(&option_font_fantasy, "Sassoon", fallback);
|
||||||
|
|
||||||
if (option_font_default != CSS_FONT_FAMILY_SANS_SERIF &&
|
if (option_font_default != PLOT_FONT_FAMILY_SANS_SERIF &&
|
||||||
option_font_default != CSS_FONT_FAMILY_SERIF &&
|
option_font_default != PLOT_FONT_FAMILY_SERIF &&
|
||||||
option_font_default != CSS_FONT_FAMILY_MONOSPACE &&
|
option_font_default != PLOT_FONT_FAMILY_MONOSPACE &&
|
||||||
option_font_default != CSS_FONT_FAMILY_CURSIVE &&
|
option_font_default != PLOT_FONT_FAMILY_CURSIVE &&
|
||||||
option_font_default != CSS_FONT_FAMILY_FANTASY)
|
option_font_default != PLOT_FONT_FAMILY_FANTASY)
|
||||||
option_font_default = CSS_FONT_FAMILY_SANS_SERIF;
|
option_font_default = PLOT_FONT_FAMILY_SANS_SERIF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -218,15 +218,14 @@ void nsfont_check_fonts(void)
|
|||||||
/**
|
/**
|
||||||
* Measure the width of a string.
|
* Measure the width of a string.
|
||||||
*
|
*
|
||||||
* \param style css_style for this text, with style->font_size.size ==
|
* \param fstyle plot style for this text
|
||||||
* CSS_FONT_SIZE_LENGTH
|
|
||||||
* \param string UTF-8 string to measure
|
* \param string UTF-8 string to measure
|
||||||
* \param length length of string
|
* \param length length of string
|
||||||
* \param width updated to width of string[0..length)
|
* \param width updated to width of string[0..length)
|
||||||
* \return true on success, false on error and error reported
|
* \return true on success, false on error and error reported
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool nsfont_width(const struct css_style *style,
|
bool nsfont_width(const plot_font_style_t *fstyle,
|
||||||
const char *string, size_t length,
|
const char *string, size_t length,
|
||||||
int *width)
|
int *width)
|
||||||
{
|
{
|
||||||
@ -235,7 +234,7 @@ bool nsfont_width(const struct css_style *style,
|
|||||||
rufl_style font_style;
|
rufl_style font_style;
|
||||||
rufl_code code;
|
rufl_code code;
|
||||||
|
|
||||||
nsfont_read_style(style, &font_family, &font_size, &font_style);
|
nsfont_read_style(fstyle, &font_family, &font_size, &font_style);
|
||||||
|
|
||||||
code = rufl_width(font_family, font_style, font_size,
|
code = rufl_width(font_family, font_style, font_size,
|
||||||
string, length,
|
string, length,
|
||||||
@ -259,8 +258,7 @@ bool nsfont_width(const struct css_style *style,
|
|||||||
/**
|
/**
|
||||||
* Find the position in a string where an x coordinate falls.
|
* Find the position in a string where an x coordinate falls.
|
||||||
*
|
*
|
||||||
* \param style css_style for this text, with style->font_size.size ==
|
* \param fstyle style for this text
|
||||||
* CSS_FONT_SIZE_LENGTH
|
|
||||||
* \param string UTF-8 string to measure
|
* \param string UTF-8 string to measure
|
||||||
* \param length length of string
|
* \param length length of string
|
||||||
* \param x x coordinate to search for
|
* \param x x coordinate to search for
|
||||||
@ -269,7 +267,7 @@ bool nsfont_width(const struct css_style *style,
|
|||||||
* \return true on success, false on error and error reported
|
* \return true on success, false on error and error reported
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool nsfont_position_in_string(const struct css_style *style,
|
bool nsfont_position_in_string(const plot_font_style_t *fstyle,
|
||||||
const char *string, size_t length,
|
const char *string, size_t length,
|
||||||
int x, size_t *char_offset, int *actual_x)
|
int x, size_t *char_offset, int *actual_x)
|
||||||
{
|
{
|
||||||
@ -278,7 +276,7 @@ bool nsfont_position_in_string(const struct css_style *style,
|
|||||||
rufl_style font_style;
|
rufl_style font_style;
|
||||||
rufl_code code;
|
rufl_code code;
|
||||||
|
|
||||||
nsfont_read_style(style, &font_family, &font_size, &font_style);
|
nsfont_read_style(fstyle, &font_family, &font_size, &font_style);
|
||||||
|
|
||||||
code = rufl_x_to_offset(font_family, font_style, font_size,
|
code = rufl_x_to_offset(font_family, font_style, font_size,
|
||||||
string, length,
|
string, length,
|
||||||
@ -303,8 +301,7 @@ bool nsfont_position_in_string(const struct css_style *style,
|
|||||||
/**
|
/**
|
||||||
* Find where to split a string to make it fit a width.
|
* Find where to split a string to make it fit a width.
|
||||||
*
|
*
|
||||||
* \param style css_style for this text, with style->font_size.size ==
|
* \param fstyle style for this text
|
||||||
* CSS_FONT_SIZE_LENGTH
|
|
||||||
* \param string UTF-8 string to measure
|
* \param string UTF-8 string to measure
|
||||||
* \param length length of string
|
* \param length length of string
|
||||||
* \param x width available
|
* \param x width available
|
||||||
@ -317,7 +314,7 @@ bool nsfont_position_in_string(const struct css_style *style,
|
|||||||
* char_offset == length]
|
* char_offset == length]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool nsfont_split(const struct css_style *style,
|
bool nsfont_split(const plot_font_style_t *fstyle,
|
||||||
const char *string, size_t length,
|
const char *string, size_t length,
|
||||||
int x, size_t *char_offset, int *actual_x)
|
int x, size_t *char_offset, int *actual_x)
|
||||||
{
|
{
|
||||||
@ -326,7 +323,7 @@ bool nsfont_split(const struct css_style *style,
|
|||||||
rufl_style font_style;
|
rufl_style font_style;
|
||||||
rufl_code code;
|
rufl_code code;
|
||||||
|
|
||||||
nsfont_read_style(style, &font_family, &font_size, &font_style);
|
nsfont_read_style(fstyle, &font_family, &font_size, &font_style);
|
||||||
|
|
||||||
code = rufl_split(font_family, font_style, font_size,
|
code = rufl_split(font_family, font_style, font_size,
|
||||||
string, length,
|
string, length,
|
||||||
@ -368,19 +365,16 @@ bool nsfont_split(const struct css_style *style,
|
|||||||
/**
|
/**
|
||||||
* Paint a string.
|
* Paint a string.
|
||||||
*
|
*
|
||||||
* \param style css_style for this text, with style->font_size.size ==
|
* \param fstyle plot style for this text
|
||||||
* CSS_FONT_SIZE_LENGTH
|
|
||||||
* \param string UTF-8 string to measure
|
* \param string UTF-8 string to measure
|
||||||
* \param length length of string
|
* \param length length of string
|
||||||
* \param x x coordinate
|
* \param x x coordinate
|
||||||
* \param y y coordinate
|
* \param y y coordinate
|
||||||
* \param scale scale to apply to font size
|
* \param scale scale to apply to font size
|
||||||
* \param bg background colour
|
|
||||||
* \param c colour for text
|
|
||||||
* \return true on success, false on error and error reported
|
* \return true on success, false on error and error reported
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool nsfont_paint(const struct css_style *style, const char *string,
|
bool nsfont_paint(const plot_font_style_t *fstyle, const char *string,
|
||||||
size_t length, int x, int y, float scale)
|
size_t length, int x, int y, float scale)
|
||||||
{
|
{
|
||||||
const char *font_family;
|
const char *font_family;
|
||||||
@ -388,7 +382,7 @@ bool nsfont_paint(const struct css_style *style, const char *string,
|
|||||||
rufl_style font_style;
|
rufl_style font_style;
|
||||||
rufl_code code;
|
rufl_code code;
|
||||||
|
|
||||||
nsfont_read_style(style, &font_family, &font_size, &font_style);
|
nsfont_read_style(fstyle, &font_family, &font_size, &font_style);
|
||||||
|
|
||||||
code = rufl_paint(font_family, font_style, font_size * scale,
|
code = rufl_paint(font_family, font_style, font_size * scale,
|
||||||
string, length, x, y,
|
string, length, x, y,
|
||||||
@ -407,40 +401,50 @@ bool nsfont_paint(const struct css_style *style, const char *string,
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a css_style to a font family, size and rufl_style.
|
* Convert a font style to a font family, size and rufl_style.
|
||||||
*
|
*
|
||||||
* \param style css_style for this text, with style->font_size.size ==
|
* \param fstyle plot style for this text
|
||||||
* CSS_FONT_SIZE_LENGTH
|
|
||||||
* \param font_family updated to font family
|
* \param font_family updated to font family
|
||||||
* \param font_size updated to font size
|
* \param font_size updated to font size
|
||||||
* \param font_style updated to font style
|
* \param font_style updated to font style
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void nsfont_read_style(const struct css_style *style,
|
void nsfont_read_style(const plot_font_style_t *fstyle,
|
||||||
const char **font_family, unsigned int *font_size,
|
const char **font_family, unsigned int *font_size,
|
||||||
rufl_style *font_style)
|
rufl_style *font_style)
|
||||||
{
|
{
|
||||||
assert(style->font_size.size == CSS_FONT_SIZE_LENGTH);
|
static const rufl_style weight_table[] = {
|
||||||
*font_size = css_len2pt(&style->font_size.value.length, style) * 16.;
|
rufl_WEIGHT_100,
|
||||||
|
rufl_WEIGHT_200,
|
||||||
|
rufl_WEIGHT_300,
|
||||||
|
rufl_WEIGHT_400,
|
||||||
|
rufl_WEIGHT_500,
|
||||||
|
rufl_WEIGHT_600,
|
||||||
|
rufl_WEIGHT_700,
|
||||||
|
rufl_WEIGHT_800,
|
||||||
|
rufl_WEIGHT_900
|
||||||
|
};
|
||||||
|
|
||||||
|
*font_size = fstyle->size * 16.;
|
||||||
if (*font_size < option_font_min_size * 1.6)
|
if (*font_size < option_font_min_size * 1.6)
|
||||||
*font_size = option_font_min_size * 1.6;
|
*font_size = option_font_min_size * 1.6;
|
||||||
if (1600 < *font_size)
|
if (1600 < *font_size)
|
||||||
*font_size = 1600;
|
*font_size = 1600;
|
||||||
|
|
||||||
switch (style->font_family) {
|
switch (fstyle->family) {
|
||||||
case CSS_FONT_FAMILY_SANS_SERIF:
|
case PLOT_FONT_FAMILY_SANS_SERIF:
|
||||||
*font_family = option_font_sans;
|
*font_family = option_font_sans;
|
||||||
break;
|
break;
|
||||||
case CSS_FONT_FAMILY_SERIF:
|
case PLOT_FONT_FAMILY_SERIF:
|
||||||
*font_family = option_font_serif;
|
*font_family = option_font_serif;
|
||||||
break;
|
break;
|
||||||
case CSS_FONT_FAMILY_MONOSPACE:
|
case PLOT_FONT_FAMILY_MONOSPACE:
|
||||||
*font_family = option_font_mono;
|
*font_family = option_font_mono;
|
||||||
break;
|
break;
|
||||||
case CSS_FONT_FAMILY_CURSIVE:
|
case PLOT_FONT_FAMILY_CURSIVE:
|
||||||
*font_family = option_font_cursive;
|
*font_family = option_font_cursive;
|
||||||
break;
|
break;
|
||||||
case CSS_FONT_FAMILY_FANTASY:
|
case PLOT_FONT_FAMILY_FANTASY:
|
||||||
*font_family = option_font_fantasy;
|
*font_family = option_font_fantasy;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -448,50 +452,13 @@ void nsfont_read_style(const struct css_style *style,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (style->font_style) {
|
if ((fstyle->flags & FONTF_ITALIC) || (fstyle->flags & FONTF_OBLIQUE)) {
|
||||||
case CSS_FONT_STYLE_ITALIC:
|
|
||||||
case CSS_FONT_STYLE_OBLIQUE:
|
|
||||||
*font_style = rufl_SLANTED;
|
*font_style = rufl_SLANTED;
|
||||||
break;
|
} else {
|
||||||
default:
|
|
||||||
*font_style = 0;
|
*font_style = 0;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (style->font_weight) {
|
*font_style |= weight_table[(fstyle->weight / 100) - 1];
|
||||||
case CSS_FONT_WEIGHT_100:
|
|
||||||
*font_style |= rufl_WEIGHT_100;
|
|
||||||
break;
|
|
||||||
case CSS_FONT_WEIGHT_200:
|
|
||||||
*font_style |= rufl_WEIGHT_200;
|
|
||||||
break;
|
|
||||||
case CSS_FONT_WEIGHT_300:
|
|
||||||
*font_style |= rufl_WEIGHT_300;
|
|
||||||
break;
|
|
||||||
case CSS_FONT_WEIGHT_NORMAL:
|
|
||||||
case CSS_FONT_WEIGHT_400:
|
|
||||||
*font_style |= rufl_WEIGHT_400;
|
|
||||||
break;
|
|
||||||
case CSS_FONT_WEIGHT_500:
|
|
||||||
*font_style |= rufl_WEIGHT_500;
|
|
||||||
break;
|
|
||||||
case CSS_FONT_WEIGHT_600:
|
|
||||||
*font_style |= rufl_WEIGHT_600;
|
|
||||||
break;
|
|
||||||
case CSS_FONT_WEIGHT_BOLD:
|
|
||||||
case CSS_FONT_WEIGHT_700:
|
|
||||||
*font_style |= rufl_WEIGHT_700;
|
|
||||||
break;
|
|
||||||
case CSS_FONT_WEIGHT_800:
|
|
||||||
*font_style |= rufl_WEIGHT_800;
|
|
||||||
break;
|
|
||||||
case CSS_FONT_WEIGHT_900:
|
|
||||||
*font_style |= rufl_WEIGHT_900;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
*font_style |= rufl_WEIGHT_400;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -210,9 +210,9 @@ void ro_gui_print_prepare(struct gui_window *g);
|
|||||||
void nsfont_init(void);
|
void nsfont_init(void);
|
||||||
bool nsfont_exists(const char *font_family);
|
bool nsfont_exists(const char *font_family);
|
||||||
const char *nsfont_fallback_font(void);
|
const char *nsfont_fallback_font(void);
|
||||||
bool nsfont_paint(const struct css_style *style, const char *string,
|
bool nsfont_paint(const plot_font_style_t *fstyle, const char *string,
|
||||||
size_t length, int x, int y, float scale);
|
size_t length, int x, int y, float scale);
|
||||||
void nsfont_read_style(const struct css_style *style,
|
void nsfont_read_style(const plot_font_style_t *fstyle,
|
||||||
const char **font_family, unsigned int *font_size,
|
const char **font_family, unsigned int *font_size,
|
||||||
rufl_style *font_style);
|
rufl_style *font_style);
|
||||||
void ro_gui_wimp_get_desktop_font(void);
|
void ro_gui_wimp_get_desktop_font(void);
|
||||||
|
@ -43,8 +43,8 @@ static bool ro_plot_path(const float *p, unsigned int n, colour fill, float widt
|
|||||||
colour c, const float transform[6]);
|
colour c, const float transform[6]);
|
||||||
static bool ro_plot_clip(int clip_x0, int clip_y0,
|
static bool ro_plot_clip(int clip_x0, int clip_y0,
|
||||||
int clip_x1, int clip_y1);
|
int clip_x1, int clip_y1);
|
||||||
static bool ro_plot_text(int x, int y, const struct css_style *style,
|
static bool ro_plot_text(int x, int y, const char *text, size_t length,
|
||||||
const char *text, size_t length, colour bg, colour c);
|
const plot_font_style_t *fstyle);
|
||||||
static bool ro_plot_disc(int x, int y, int radius, const plot_style_t *style);
|
static bool ro_plot_disc(int x, int y, int radius, const plot_style_t *style);
|
||||||
static bool ro_plot_arc(int x, int y, int radius, int angle1, int angle2,
|
static bool ro_plot_arc(int x, int y, int radius, int angle1, int angle2,
|
||||||
const plot_style_t *style);
|
const plot_style_t *style);
|
||||||
@ -394,20 +394,21 @@ bool ro_plot_clip(int clip_x0, int clip_y0,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool ro_plot_text(int x, int y, const struct css_style *style,
|
bool ro_plot_text(int x, int y, const char *text, size_t length,
|
||||||
const char *text, size_t length, colour bg, colour c)
|
const plot_font_style_t *fstyle)
|
||||||
{
|
{
|
||||||
os_error *error;
|
os_error *error;
|
||||||
|
|
||||||
error = xcolourtrans_set_font_colours(font_CURRENT,
|
error = xcolourtrans_set_font_colours(font_CURRENT,
|
||||||
bg << 8, c << 8, 14, 0, 0, 0);
|
fstyle->background << 8, fstyle->foreground << 8,
|
||||||
|
14, 0, 0, 0);
|
||||||
if (error) {
|
if (error) {
|
||||||
LOG(("xcolourtrans_set_font_colours: 0x%x: %s",
|
LOG(("xcolourtrans_set_font_colours: 0x%x: %s",
|
||||||
error->errnum, error->errmess));
|
error->errnum, error->errmess));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return nsfont_paint(style, text, length,
|
return nsfont_paint(fstyle, text, length,
|
||||||
ro_plot_origin_x + x * 2,
|
ro_plot_origin_x + x * 2,
|
||||||
ro_plot_origin_y - y * 2,
|
ro_plot_origin_y - y * 2,
|
||||||
ro_plot_scale);
|
ro_plot_scale);
|
||||||
|
@ -102,8 +102,8 @@ static bool print_fonts_plot_line(int x0, int y0, int x1, int y1, const plot_sty
|
|||||||
static bool print_fonts_plot_polygon(const int *p, unsigned int n, const plot_style_t *style);
|
static bool print_fonts_plot_polygon(const int *p, unsigned int n, const plot_style_t *style);
|
||||||
static bool print_fonts_plot_clip(int clip_x0, int clip_y0,
|
static bool print_fonts_plot_clip(int clip_x0, int clip_y0,
|
||||||
int clip_x1, int clip_y1);
|
int clip_x1, int clip_y1);
|
||||||
static bool print_fonts_plot_text(int x, int y, const struct css_style *style,
|
static bool print_fonts_plot_text(int x, int y, const char *text, size_t length,
|
||||||
const char *text, size_t length, colour bg, colour c);
|
const plot_font_style_t *fstyle);
|
||||||
static bool print_fonts_plot_disc(int x, int y, int radius, const plot_style_t *style);
|
static bool print_fonts_plot_disc(int x, int y, int radius, const plot_style_t *style);
|
||||||
static bool print_fonts_plot_arc(int x, int y, int radius, int angle1, int angle2, const plot_style_t *style);
|
static bool print_fonts_plot_arc(int x, int y, int radius, int angle1, int angle2, const plot_style_t *style);
|
||||||
static bool print_fonts_plot_bitmap(int x, int y, int width, int height,
|
static bool print_fonts_plot_bitmap(int x, int y, int width, int height,
|
||||||
@ -852,15 +852,15 @@ bool print_fonts_plot_path(const float *p, unsigned int n, colour fill, float wi
|
|||||||
* Plotter for text plotting during font listing.
|
* Plotter for text plotting during font listing.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool print_fonts_plot_text(int x, int y, const struct css_style *style,
|
bool print_fonts_plot_text(int x, int y, const char *text, size_t length,
|
||||||
const char *text, size_t length, colour bg, colour c)
|
const plot_font_style_t *fstyle)
|
||||||
{
|
{
|
||||||
const char *font_family;
|
const char *font_family;
|
||||||
unsigned int font_size;
|
unsigned int font_size;
|
||||||
rufl_style font_style;
|
rufl_style font_style;
|
||||||
rufl_code code;
|
rufl_code code;
|
||||||
|
|
||||||
nsfont_read_style(style, &font_family, &font_size, &font_style);
|
nsfont_read_style(fstyle, &font_family, &font_size, &font_style);
|
||||||
|
|
||||||
code = rufl_paint_callback(font_family, font_style, font_size,
|
code = rufl_paint_callback(font_family, font_style, font_size,
|
||||||
text, length, 0, 0, print_fonts_callback, 0);
|
text, length, 0, 0, print_fonts_callback, 0);
|
||||||
|
@ -44,8 +44,8 @@ static bool ro_save_draw_path(const float *p, unsigned int n, colour fill,
|
|||||||
float width, colour c, const float transform[6]);
|
float width, colour c, const float transform[6]);
|
||||||
static bool ro_save_draw_clip(int clip_x0, int clip_y0,
|
static bool ro_save_draw_clip(int clip_x0, int clip_y0,
|
||||||
int clip_x1, int clip_y1);
|
int clip_x1, int clip_y1);
|
||||||
static bool ro_save_draw_text(int x, int y, const struct css_style *style,
|
static bool ro_save_draw_text(int x, int y, const char *text, size_t length,
|
||||||
const char *text, size_t length, colour bg, colour c);
|
const plot_font_style_t *fstyle);
|
||||||
static bool ro_save_draw_disc(int x, int y, int radius, const plot_style_t *style);
|
static bool ro_save_draw_disc(int x, int y, int radius, const plot_style_t *style);
|
||||||
static bool ro_save_draw_arc(int x, int y, int radius, int angle1, int angle2,
|
static bool ro_save_draw_arc(int x, int y, int radius, int angle1, int angle2,
|
||||||
const plot_style_t *style);
|
const plot_style_t *style);
|
||||||
@ -348,18 +348,19 @@ bool ro_save_draw_clip(int clip_x0, int clip_y0,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool ro_save_draw_text(int x, int y, const struct css_style *style,
|
bool ro_save_draw_text(int x, int y, const char *text, size_t length,
|
||||||
const char *text, size_t length, colour bg, colour c)
|
const plot_font_style_t *fstyle)
|
||||||
{
|
{
|
||||||
pencil_code code;
|
pencil_code code;
|
||||||
const char *font_family;
|
const char *font_family;
|
||||||
unsigned int font_size;
|
unsigned int font_size;
|
||||||
rufl_style font_style;
|
rufl_style font_style;
|
||||||
|
|
||||||
nsfont_read_style(style, &font_family, &font_size, &font_style);
|
nsfont_read_style(fstyle, &font_family, &font_size, &font_style);
|
||||||
|
|
||||||
code = pencil_text(ro_save_draw_diagram, x * 2, -y * 2, font_family,
|
code = pencil_text(ro_save_draw_diagram, x * 2, -y * 2, font_family,
|
||||||
font_style, font_size, text, length, c << 8);
|
font_style, font_size, text, length,
|
||||||
|
fstyle->foreground << 8);
|
||||||
if (code != pencil_OK)
|
if (code != pencil_OK)
|
||||||
return ro_save_draw_error(code);
|
return ro_save_draw_error(code);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user