From 058fcac22516008f3247cad9641cc91139b21e8c Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sun, 10 Aug 2008 09:57:41 +0000 Subject: Added code to set correct font. svn path=/trunk/netsurf/; revision=4986 --- amiga/font.c | 97 +++++++++++++++++++++++++++++++++++++ amiga/font.h | 26 ++++++++++ amiga/gui.c | 143 ++++++++++++++++++++++++++++++++++++++----------------- amiga/gui.h | 2 + amiga/plotters.c | 76 ++++++++++++++--------------- 5 files changed, 260 insertions(+), 84 deletions(-) create mode 100755 amiga/font.h (limited to 'amiga') diff --git a/amiga/font.c b/amiga/font.c index e780612a0..13651dc51 100644 --- a/amiga/font.c +++ b/amiga/font.c @@ -22,6 +22,10 @@ #include "render/font.h" #include "amiga/gui.h" #include +#include +#include +#include "amiga/font.h" +#include "desktop/options.h" static bool nsfont_width(const struct css_style *style, const char *string, size_t length, @@ -45,6 +49,7 @@ bool nsfont_width(const struct css_style *style, const char *string, size_t length, int *width) { + ami_open_font(style); *width = TextLength(currp,string,length); return true; } @@ -68,6 +73,7 @@ bool nsfont_position_in_string(const struct css_style *style, { struct TextExtent extent; + ami_open_font(style); *char_offset = TextFit(currp,string,length, &extent,NULL,1,x,32767); @@ -101,6 +107,7 @@ bool nsfont_split(const struct css_style *style, ULONG co; char *charp; + ami_open_font(style); co = TextFit(currp,string,length, &extent,NULL,1,x,32767); @@ -116,3 +123,93 @@ bool nsfont_split(const struct css_style *style, return true; } + +void ami_open_font(struct css_style *style) +{ + struct TextFont *tfont; + struct TextAttr tattr; + +/* + css_font_family font_family; + css_font_style font_style; + css_font_variant font_variant; +see css_enum.h +*/ + switch(style->font_family) + { + case CSS_FONT_FAMILY_SANS_SERIF: + tattr.ta_Name = option_font_sans; + break; + + case CSS_FONT_FAMILY_SERIF: + tattr.ta_Name = option_font_serif; + break; + + case CSS_FONT_FAMILY_MONOSPACE: + tattr.ta_Name = option_font_mono; + break; + + case CSS_FONT_FAMILY_CURSIVE: + tattr.ta_Name = option_font_cursive; + break; + + case CSS_FONT_FAMILY_FANTASY: + tattr.ta_Name = option_font_fantasy; + break; + + default: + tattr.ta_Name = option_font_sans; + //printf("font family: %ld\n",style->font_family); + break; + } + + switch(style->font_style) + { + case CSS_FONT_STYLE_ITALIC: + tattr.ta_Style = FSB_ITALIC; + break; + + case CSS_FONT_STYLE_OBLIQUE: + tattr.ta_Style = FSB_BOLD; + break; + + default: + tattr.ta_Style = FS_NORMAL; + //printf("font style: %ld\n",style->font_style); + break; + } + + switch(style->font_variant) + { + default: + //printf("font variant: %ld\n",style->font_variant); + break; + } + + switch(style->font_size.size) + { + case CSS_FONT_SIZE_LENGTH: + tattr.ta_YSize = (UWORD)style->font_size.value.length.value; + break; + default: + printf("FONT SIZE TYPE: %ld\n",style->font_size.size); + break; + } + //printf("%lf %ld\n",style->font_size.value.length.value,(UWORD)style->font_size.value.length.value); + + tattr.ta_Name = "DejaVu Sans.font"; +// tattr.ta_Style = FS_NORMAL; // | FSB_ANTIALIASED; + tattr.ta_Flags = 0; //FPB_PROPORTIONAL; +// see graphics/text.h + + tfont = OpenDiskFont(&tattr); + + if(tfont) + { + SetRPAttrs(currp, + RPTAG_Font,tfont, + TAG_DONE); + } + + CloseFont(tfont); +} diff --git a/amiga/font.h b/amiga/font.h new file mode 100755 index 000000000..857bee429 --- /dev/null +++ b/amiga/font.h @@ -0,0 +1,26 @@ +/* + * Copyright 2008 Chris Young + * + * 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 . + */ + +#ifndef AMIGA_FONT_H +#define AMIGA_FONT_H + +#include "css/css.h" + +void ami_open_font(struct css_style *); + +#endif diff --git a/amiga/gui.c b/amiga/gui.c index c03cbb6d2..9975b51fe 100755 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -62,6 +62,8 @@ struct Device *TimerBase; struct TimerIFace *ITimer; struct Screen *scrn; +bool win_destroyed = false; + void ami_update_buttons(struct gui_window *); void gui_init(int argc, char** argv) @@ -131,16 +133,31 @@ void gui_init(int argc, char** argv) adblock_stylesheet_url = "file://NetSurf/Resources/adblock.css"; options_read("Resources/Options"); - if (!option_cookie_file) + if(!option_cookie_file) option_cookie_file = strdup("Resources/Cookies"); /* - if (!option_cookie_jar) + if(!option_cookie_jar) option_cookie_jar = strdup("resources/cookiejar"); */ - if (!option_ca_bundle) - option_ca_bundle = strdup("devs:curl-ca-bundle.crt"); + if(!option_ca_bundle) + option_ca_bundle = strdup("devs:curl-ca-bundle.crt"); + + if(!option_font_sans) + option_font_sans = strdup("DejaVu Sans.font"); + + if(!option_font_serif) + option_font_serif = strdup("DejaVu Serif.font"); + + if(!option_font_mono) + option_font_mono = strdup("DejaVu Sans Mono.font"); + + if(!option_font_cursive) + option_font_cursive = strdup("DejaVu Sans.font"); + + if(!option_font_fantasy) + option_font_fantasy = strdup("DejaVu Serif.font"); plot=amiplot; @@ -160,9 +177,6 @@ void gui_init2(int argc, char** argv) if ((option_homepage_url == NULL) || (option_homepage_url[0] == '\0')) option_homepage_url = strdup(NETSURF_HOMEPAGE); -// if (option_homepage_url != NULL && option_homepage_url[0] != '\0') -// addr = option_homepage_url; - scrn = OpenScreenTags(NULL, /* SA_Width,1024, @@ -179,7 +193,7 @@ void gui_init2(int argc, char** argv) void ami_get_msg(void) { struct IntuiMessage *message = NULL; - ULONG class,code,result,storage = 0,x,y; + ULONG class,code,result,storage = 0,x,y,xs,ys; struct nsObject *node; struct nsObject *nnode; struct gui_window *gwin,*destroywin=NULL; @@ -198,11 +212,13 @@ void ami_get_msg(void) { case WMHI_MOUSEMOVE: GetAttr(IA_Left,gwin->gadgets[GID_BROWSER],&storage); - x = gwin->win->MouseX - storage; + GetAttr(SCROLLER_Top,gwin->objects[OID_HSCROLL],&xs); + x = gwin->win->MouseX - storage+xs; GetAttr(IA_Top,gwin->gadgets[GID_BROWSER],&storage); - y = gwin->win->MouseY - storage; + GetAttr(SCROLLER_Top,gwin->objects[OID_VSCROLL],&ys); + y = gwin->win->MouseY - storage + ys; - if(x>=0 && y>=0 &&x<800 && y<600) + if((x>=xs) && (y>=ys) && (x<800+xs) && y<(600+ys)) { browser_window_mouse_track(gwin->bw,0,x,y); } @@ -210,11 +226,13 @@ void ami_get_msg(void) case WMHI_MOUSEBUTTONS: GetAttr(IA_Left,gwin->gadgets[GID_BROWSER],&storage); - x = gwin->win->MouseX - storage; + GetAttr(SCROLLER_Top,gwin->objects[OID_HSCROLL],&xs); + x = gwin->win->MouseX - storage+xs; GetAttr(IA_Top,gwin->gadgets[GID_BROWSER],&storage); - y = gwin->win->MouseY - storage; + GetAttr(SCROLLER_Top,gwin->objects[OID_VSCROLL],&ys); + y = gwin->win->MouseY - storage + ys; - if(x>=0 && y>=0 &&x<800 && y<600) + if((x>=xs) && (y>=ys) && (x<800+xs) && y<(600+ys)) { code = code>>16; printf("buttons: %lx\n",code); @@ -243,7 +261,7 @@ void ami_get_msg(void) case GID_URL: GetAttr(STRINGA_TextVal,gwin->gadgets[GID_URL],&storage); browser_window_go(gwin->bw,(char *)storage,NULL,true); - printf("%s\n",(char *)storage); + //printf("%s\n",(char *)storage); break; case GID_HOME: @@ -275,32 +293,56 @@ void ami_get_msg(void) ami_update_buttons(gwin); break; + + default: + printf("GADGET: %ld\n",(result & WMHI_GADGETMASK)); + break; } break; case WMHI_VANILLAKEY: storage = result & WMHI_GADGETMASK; - printf("%lx\n",storage); + //printf("%lx\n",storage); browser_window_key_press(gwin->bw,storage); break; case WMHI_CLOSEWINDOW: - destroywin=gwin; + browser_window_destroy(gwin->bw); + //destroywin=gwin; break; default: + printf("class: %ld\n",(result & WMHI_CLASSMASK)); break; } // ReplyMsg((struct Message *)message); } - node = nnode; - if(destroywin) + + if(win_destroyed) { - browser_window_destroy(destroywin->bw); - destroywin=NULL; + /* we can't be sure what state our window_list is in, so let's + jump out of the function and start again */ + + win_destroyed = false; + return; } + +/* + while((result = RA_HandleInput(gwin->objects[OID_VSCROLL],&code)) != WMHI_LASTMSG) + { + switch(result & WMHI_CLASSMASK) // class + { + default: + //case WMHI_GADGETUP: + //switch(result & WMHI_GADGETMASK) //gadaddr->GadgetID) //result & WMHI_GADGETMASK) + printf("vscroller %ld %ld\n",(result & WMHI_CLASSMASK),(result & WMHI_GADGETMASK)); + break; + } + } +*/ + node = nnode; } } @@ -427,8 +469,9 @@ struct gui_window *gui_create_browser_window(struct browser_window *bw, WINDOW_HorizProp,1, WINDOW_VertProp,1, WINDOW_Position, WPOS_CENTERSCREEN, + WINDOW_CharSet,106, WINDOW_ParentGroup, gwin->gadgets[GID_MAIN] = VGroupObject, -// LAYOUT_CharSet,106, + LAYOUT_CharSet,106, LAYOUT_SpaceOuter, TRUE, LAYOUT_AddChild, HGroupObject, LAYOUT_AddChild, gwin->gadgets[GID_BACK] = ButtonObject, @@ -526,11 +569,21 @@ struct gui_window *gui_create_browser_window(struct browser_window *bw, EndGroup, EndWindow; - gwin->win = (struct Window *)RA_OpenWindow(gwin->objects[OID_MAIN]); + gwin->win = (struct Window *)RA_OpenWindow(gwin->objects[OID_MAIN]); + + gwin->bw = bw; +// curwin = gwin; //test + currp = &gwin->rp; // WINDOW.CLASS: &gwin->rp; //gwin->win->RPort; - gwin->bw = bw; - curwin = gwin; //test - currp = &gwin->rp; // WINDOW.CLASS: &gwin->rp; //gwin->win->RPort; + GetAttr(WINDOW_HorizObject,gwin->objects[OID_MAIN],(ULONG *)&gwin->objects[OID_HSCROLL]); + GetAttr(WINDOW_VertObject,gwin->objects[OID_MAIN],(ULONG *)&gwin->objects[OID_VSCROLL]); + + + RefreshSetGadgetAttrs((APTR)gwin->objects[OID_VSCROLL],gwin->win,NULL, + GA_RelVerify,TRUE, + GA_Immediate,TRUE, + GA_ID,OID_VSCROLL, + TAG_DONE); gwin->node = AddObject(window_list,AMINS_WINDOW); gwin->node->objstruct = gwin; @@ -551,6 +604,8 @@ void gui_window_destroy(struct gui_window *g) gui_quit(); exit(0); } + + win_destroyed = true; } void gui_window_set_title(struct gui_window *g, const char *title) @@ -566,14 +621,14 @@ void gui_window_redraw(struct gui_window *g, int x0, int y0, int x1, int y1) void gui_window_redraw_window(struct gui_window *g) { struct content *c; - Object *hscroller,*vscroller; +// Object *hscroller,*vscroller; ULONG hcurrent,vcurrent; // will also need bitmap_width and bitmap_height once resizing windows is working - GetAttr(WINDOW_HorizObject,g->objects[OID_MAIN],(ULONG *)&hscroller); - GetAttr(WINDOW_VertObject,g->objects[OID_MAIN],(ULONG *)&vscroller); - GetAttr(SCROLLER_Top,hscroller,&hcurrent); - GetAttr(SCROLLER_Top,vscroller,&vcurrent); +// GetAttr(WINDOW_HorizObject,g->objects[OID_MAIN],(ULONG *)&hscroller); +// GetAttr(WINDOW_VertObject,g->objects[OID_MAIN],(ULONG *)&vscroller); + GetAttr(SCROLLER_Top,g->objects[OID_HSCROLL],&hcurrent); + GetAttr(SCROLLER_Top,g->objects[OID_VSCROLL],&vcurrent); DebugPrintF("REDRAW2\n"); @@ -589,10 +644,10 @@ printf("%ld,%ld hc vc\n",hcurrent,vcurrent); if (c->locked) return; // if (c->type == CONTENT_HTML) scale = 1; - - content_redraw(c, 0,0,800,600, +printf("not locked\n"); + content_redraw(c, -hcurrent,-vcurrent,800,600, 0,0,800,600, - g->bw->scale, 0xFFFFFF); + g->bw->scale,0xFFFFFF); current_redraw_browser = NULL; @@ -652,20 +707,20 @@ bool gui_window_get_scroll(struct gui_window *g, int *sx, int *sy) void gui_window_set_scroll(struct gui_window *g, int sx, int sy) { - Object *hscroller,*vscroller; +// Object *hscroller,*vscroller; printf("set scr %ld,%ld\n",sx,sy); // will also need bitmap_width and bitmap_height once resizing windows is working - GetAttr(WINDOW_HorizObject,g->objects[OID_MAIN],(ULONG *)&hscroller); - GetAttr(WINDOW_VertObject,g->objects[OID_MAIN],(ULONG *)&vscroller); +// GetAttr(WINDOW_HorizObject,g->objects[OID_MAIN],(ULONG *)&hscroller); +// GetAttr(WINDOW_VertObject,g->objects[OID_MAIN],(ULONG *)&vscroller); - RefreshSetGadgetAttrs((APTR)vscroller,g->win,NULL, + RefreshSetGadgetAttrs((APTR)g->objects[OID_VSCROLL],g->win,NULL, SCROLLER_Top,sy, TAG_DONE); - RefreshSetGadgetAttrs((APTR)hscroller,g->win,NULL, + RefreshSetGadgetAttrs((APTR)g->objects[OID_HSCROLL],g->win,NULL, SCROLLER_Top,sx, TAG_DONE); } @@ -701,23 +756,23 @@ void gui_window_get_dimensions(struct gui_window *g, int *width, int *height, void gui_window_update_extent(struct gui_window *g) { - Object *hscroller,*vscroller; +// Object *hscroller,*vscroller; printf("upd ext %ld,%ld\n",g->bw->current_content->width, // * g->bw->scale, g->bw->current_content->height); // * g->bw->scale); // will also need bitmap_width and bitmap_height once resizing windows is working - GetAttr(WINDOW_HorizObject,g->objects[OID_MAIN],(ULONG *)&hscroller); - GetAttr(WINDOW_VertObject,g->objects[OID_MAIN],(ULONG *)&vscroller); +// GetAttr(WINDOW_HorizObject,g->objects[OID_MAIN],(ULONG *)&hscroller); +// GetAttr(WINDOW_VertObject,g->objects[OID_MAIN],(ULONG *)&vscroller); - RefreshSetGadgetAttrs((APTR)vscroller,g->win,NULL, + RefreshSetGadgetAttrs((APTR)g->objects[OID_VSCROLL],g->win,NULL, SCROLLER_Total,g->bw->current_content->height, SCROLLER_Visible,600, SCROLLER_Top,0, TAG_DONE); - RefreshSetGadgetAttrs((APTR)hscroller,g->win,NULL, + RefreshSetGadgetAttrs((APTR)g->objects[OID_HSCROLL],g->win,NULL, SCROLLER_Total,g->bw->current_content->width, SCROLLER_Visible,800, SCROLLER_Top,0, diff --git a/amiga/gui.h b/amiga/gui.h index a8c8e28af..e7bffb7d1 100755 --- a/amiga/gui.h +++ b/amiga/gui.h @@ -48,6 +48,8 @@ enum enum { OID_MAIN=0, + OID_VSCROLL, + OID_HSCROLL, OID_LAST }; diff --git a/amiga/plotters.c b/amiga/plotters.c index 1c853eeee..b4c82d15c 100755 --- a/amiga/plotters.c +++ b/amiga/plotters.c @@ -19,11 +19,14 @@ #include "amiga/plotters.h" #include "amiga/gui.h" #include "amiga/bitmap.h" +#include "amiga/font.h" #include #include #include #include +#include // for debugprintf only + static clipx,clipy; struct plotter_table plot; @@ -47,7 +50,7 @@ const struct plotter_table amiplot = { bool ami_clg(colour c) { - printf("clg %lx\n",c); + DebugPrintF("clg %lx\n",c); p96RectFill(currp,0,0,clipx,clipy, p96EncodeColor(RGBFB_A8B8G8R8,c)); @@ -58,31 +61,39 @@ bool ami_clg(colour c) bool ami_rectangle(int x0, int y0, int width, int height, int line_width, colour c, bool dotted, bool dashed) { - printf("rect\n"); + SetRPAttrs(currp,RPTAG_APenColor,p96EncodeColor(RGBFB_A8B8G8R8,c), + TAG_DONE); + Move(currp,x0,y0); + Draw(currp,x0+width,y0); + Draw(currp,x0+width,y0+height); + Draw(currp,x0,y0+height); + Draw(currp,x0,y0); + return true; } bool ami_line(int x0, int y0, int x1, int y1, int width, colour c, bool dotted, bool dashed) { - printf("line\n"); + DebugPrintF("line\n"); SetRPAttrs(currp,RPTAG_APenColor,p96EncodeColor(RGBFB_A8B8G8R8,c), TAG_DONE); Move(currp,x0,y0); Draw(currp,x1,y1); // NB: does not support width,dotted,dashed +/*There is the line pattern in the rastport, would that help? There are macros in graphics/gfxmacros.h that do it. */ return true; } bool ami_polygon(int *p, unsigned int n, colour fill) { - printf("poly\n"); + DebugPrintF("poly\n"); return true; } bool ami_fill(int x0, int y0, int x1, int y1, colour c) { - printf("fill\n"); + DebugPrintF("fill\n"); p96RectFill(currp,x0,y0,x1,y1, p96EncodeColor(RGBFB_A8B8G8R8,c)); return true; @@ -113,39 +124,12 @@ bool ami_text(int x, int y, const struct css_style *style, css_font_style font_style; css_font_variant font_variant; css_font_weight font_weight; - - struct { - enum { CSS_HEIGHT_INHERIT, - CSS_HEIGHT_AUTO, - CSS_HEIGHT_LENGTH, - CSS_HEIGHT_NOT_SET } height; - struct css_length length; - } height; - - struct { - enum { CSS_LETTER_SPACING_INHERIT, - CSS_LETTER_SPACING_NORMAL, - CSS_LETTER_SPACING_LENGTH, - CSS_LETTER_SPACING_NOT_SET } letter_spacing; - struct css_length length; - } letter_spacing; - - struct { - enum { CSS_LINE_HEIGHT_INHERIT, - CSS_LINE_HEIGHT_ABSOLUTE, - CSS_LINE_HEIGHT_LENGTH, - CSS_LINE_HEIGHT_PERCENT, - CSS_LINE_HEIGHT_NOT_SET } size; - union { - float absolute; - struct css_length length; - float percent; - } value; - } line_height; */ + ami_open_font(style); SetRPAttrs(currp,RPTAG_APenColor,p96EncodeColor(RGBFB_A8B8G8R8,c), RPTAG_BPenColor,p96EncodeColor(RGBFB_A8B8G8R8,bg), +// RPTAG_Font,tfont, TAG_DONE); Move(currp,x,y); Text(currp,text,length); @@ -154,7 +138,7 @@ bool ami_text(int x, int y, const struct css_style *style, bool ami_disc(int x, int y, int radius, colour c, bool filled) { - printf("disc\n"); + DebugPrintF("disc\n"); SetRPAttrs(currp,RPTAG_APenColor,p96EncodeColor(RGBFB_A8B8G8R8,c), TAG_DONE); DrawEllipse(currp,x,y,radius,radius); // NB: does not support fill, need to use AreaCircle for that @@ -164,7 +148,9 @@ bool ami_disc(int x, int y, int radius, colour c, bool filled) bool ami_arc(int x, int y, int radius, int angle1, int angle2, colour c) { - printf("arc\n"); +/* http://www.crbond.com/primitives.htm +CommonFuncsPPC.lha */ + DebugPrintF("arc\n"); return true; } @@ -173,7 +159,7 @@ bool ami_bitmap(int x, int y, int width, int height, { struct RenderInfo ri; -printf("bitmap plotter\n"); +DebugPrintF("bitmap plotter\n"); // ami_fill(x,y,x+width,y+height,bg); @@ -190,7 +176,17 @@ bool ami_bitmap_tile(int x, int y, int width, int height, struct bitmap *bitmap, colour bg, bool repeat_x, bool repeat_y) { - printf("bitmap tile plotter\n"); + struct RenderInfo ri; + +DebugPrintF("bitmap tile plotter\n"); +/* not implemented properly - needs to tile! */ + + ri.Memory = bitmap->pixdata; + ri.BytesPerRow = bitmap->width * 4; + ri.RGBFormat = RGBFB_R8G8B8A8; + + p96WritePixelArray((struct RenderInfo *)&ri,0,0,currp,x,y,width,height); + return true; } @@ -208,13 +204,13 @@ bool ami_group_end(void) bool ami_flush(void) { - printf("flush\n"); + DebugPrintF("flush\n"); return true; } bool ami_path(float *p, unsigned int n, colour fill, float width, colour c, float *transform) { - printf("path\n"); + DebugPrintF("path\n"); return true; } -- cgit v1.2.3