⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dw_style.c

📁 嵌入式下基于MiniGUI的Web Browser
💻 C
📖 第 1 页 / 共 3 页
字号:
/* * File: dw_style.c * * Copyright (C) 2001-2003 Sebastian Geerken <S.Geerken@ping.de> * * This program 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; either version 2 of the License, or * (at your option) any later version. */#include <stdio.h>#include <stdlib.h>#include <string.h>#include <ctype.h>#include <minigui/common.h>#include <minigui/gdi.h>#include <glib.h>#include "mgdconfig.h"#include "dw_style.h"#include "dw_widget.h"#define DEBUG_LEVEL 10#include "debug.h"#define EQUIV(a, b) (((a) && (b)) || (!(a) && !(b)))#define Dw_style_font_ref(font)   ((font)->ref_count++)#define Dw_style_font_unref(font) if (--((font)->ref_count) == 0) \                                     Dw_style_font_remove (font)#define Dw_style_color_ref(color)   ((color)->ref_count++)#define Dw_style_color_unref(color) if (--((color)->ref_count) == 0) \                                       Dw_style_color_remove (color)#define Dw_style_shaded_color_ref(color)   ((color)->ref_count++)#define Dw_style_shaded_color_unref(color) if (--((color)->ref_count) == 0) \                                              Dw_style_shaded_color_remove \                                                 (color) \static GHashTable *fonts_table;static GHashTable *colors_table;static GHashTable *shaded_colors_table;static gint styles_num = 0;/* Used by a_Dw_style_numtostr(). */static const char   *roman_I0[] ={"I","II","III","IV","V","VI","VII","VIII","IX"},   *roman_I1[] ={"X","XX","XXX","XL","L","LX","LXX","LXXX","XC"},   *roman_I2[] ={"C","CC","CCC","CD","D","DC","DCC","DCCC","CM"},   *roman_I3[] ={"M","MM","MMM","MMMM"};static gint Dw_style_font_equal (gconstpointer v1, gconstpointer v2);static guint Dw_style_font_hash (gconstpointer key);static void Dw_style_font_remove (DwStyleFont *font);static void Dw_style_color_remove (DwStyleColor *color);static void Dw_style_shaded_color_remove (DwStyleShadedColor *color);/* ---------------------------------------------------------------------- * *    Initialization / Cleaning up * * ---------------------------------------------------------------------- *//* * Initialize the DwStyle submodule. */void a_Dw_style_init (void){   fonts_table = g_hash_table_new (Dw_style_font_hash, Dw_style_font_equal);   colors_table = g_hash_table_new (g_direct_hash, g_direct_equal);   shaded_colors_table = g_hash_table_new (g_direct_hash, g_direct_equal);}/* * Called by a_Dw_style_freeall. */static void Dw_style_count_fonts (gpointer key,                                  gpointer value,                                  gpointer user_data){   DwStyleFont *font = (DwStyleFont*) key;   gint *count = (int*)user_data;   count[0]++;   count[1] += font->ref_count;}/* * Called by a_Dw_style_freeall. */static void Dw_style_count_colors (gpointer key,                                   gpointer value,                                   gpointer user_data){   DwStyleColor *color = (DwStyleColor*) value;   gint *count = (int*)user_data;   count[0]++;   count[1] += color->ref_count;}/* * Called by a_Dw_style_freeall. */static void Dw_style_count_shaded_colors (gpointer key,                                          gpointer value,                                          gpointer user_data){   DwStyleShadedColor *color = (DwStyleShadedColor*) value;   gint *count = (int*)user_data;   count[0]++;   count[1] += color->ref_count;}/* * Free variables used by DwStyle, and do a check whether memory * management works properly. */void a_Dw_style_freeall (void){   gint count[2];   if (styles_num)      g_warning ("%d styles left", styles_num);   count[0] = count[1] = 0;   g_hash_table_foreach (fonts_table, Dw_style_count_fonts, count);   if (count[0] || count[1])      g_warning ("%d fonts (%d references) left", count[0], count[1]);   count[0] = count[1] = 0;   g_hash_table_foreach (colors_table, Dw_style_count_colors, count);   if (count[0] || count[1])      g_warning ("%d colors (%d references) left", count[0], count[1]);   count[0] = count[1] = 0;   g_hash_table_foreach (shaded_colors_table, Dw_style_count_shaded_colors,                         count);   if (count[0] || count[1])      g_warning ("%d shaded colors (%d references) left", count[0], count[1]);   g_hash_table_destroy (fonts_table);   g_hash_table_destroy (colors_table);}/* ---------------------------------------------------------------------- * *    Styles * * ---------------------------------------------------------------------- *//* * Set all style fields except font and color to reasonable defaults. */void a_Dw_style_init_values (DwStyle *style_attrs, HWND wnd){   style_attrs->x_link = -1;//   style_attrs->x_tooltip = NULL; /* fixed */   style_attrs->text_decoration = 0;   style_attrs->text_align = DW_STYLE_TEXT_ALIGN_LEFT;   style_attrs->list_style_type = DW_STYLE_LIST_STYLE_TYPE_DISC;   style_attrs->valign = DW_STYLE_VALIGN_MIDDLE;   style_attrs->background_color = NULL;   style_attrs->width = DW_STYLE_LENGTH_AUTO;   style_attrs->height = DW_STYLE_LENGTH_AUTO;   a_Dw_style_box_set_val (&style_attrs->margin, 0);   a_Dw_style_box_set_val (&style_attrs->border_width, 0);   a_Dw_style_box_set_val (&style_attrs->padding, 0);   a_Dw_style_box_set_border_color (style_attrs, NULL);   a_Dw_style_box_set_border_style (style_attrs, DW_STYLE_BORDER_NONE);   style_attrs->border_spacing = 0;   style_attrs->display = DW_STYLE_DISPLAY_INLINE;   style_attrs->white_space = DW_STYLE_WHITE_SPACE_NORMAL;}/* * Reset those style attributes to their standard values, which are * not inherited, according to CSS. */void a_Dw_style_reset_values (DwStyle *style_attrs){   style_attrs->x_link = -1;//   style_attrs->x_tooltip = NULL; /* fixed */   style_attrs->background_color = NULL;   style_attrs->text_align = DW_STYLE_TEXT_ALIGN_LEFT; /* ??? */   style_attrs->valign = DW_STYLE_VALIGN_MIDDLE;   style_attrs->text_align_char = '.';   style_attrs->background_color = NULL;   style_attrs->width = DW_STYLE_LENGTH_AUTO;   style_attrs->height = DW_STYLE_LENGTH_AUTO;   a_Dw_style_box_set_val (&style_attrs->margin, 0);   a_Dw_style_box_set_val (&style_attrs->border_width, 0);   a_Dw_style_box_set_val (&style_attrs->padding, 0);   a_Dw_style_box_set_border_color (style_attrs, NULL);   a_Dw_style_box_set_border_style (style_attrs, DW_STYLE_BORDER_NONE);   style_attrs->border_spacing = 0;   style_attrs->display = DW_STYLE_DISPLAY_INLINE;   style_attrs->white_space = DW_STYLE_WHITE_SPACE_NORMAL;}/* * Return a new DwStyle, with increased reference pointer. */DwStyle* a_Dw_style_new (DwStyle *style_attrs, HWND wnd){   DwStyle *style;   style = g_new (DwStyle, 1);   *style = *style_attrs;   style->ref_count = 1;   Dw_style_font_ref (style->font);   Dw_style_color_ref (style->color);   if (style->background_color)      Dw_style_color_ref (style->background_color);   if (style->border_color.top)      Dw_style_shaded_color_ref (style->border_color.top);   if (style->border_color.right)      Dw_style_shaded_color_ref (style->border_color.right);   if (style->border_color.bottom)      Dw_style_shaded_color_ref (style->border_color.bottom);   if (style->border_color.left)      Dw_style_shaded_color_ref (style->border_color.left);   /* fixed *///   if (style->x_tooltip)//////////////////      a_Dw_tooltip_ref (style->x_tooltip);   /* fixed */   styles_num++;   return style;}/* * Remove a style (called when ref_count == 0). */void Dw_style_remove (DwStyle *style){   Dw_style_font_unref (style->font);   Dw_style_color_unref (style->color);   if (style->background_color)      Dw_style_color_unref (style->background_color);   if (style->border_color.top)      Dw_style_shaded_color_unref (style->border_color.top);   if (style->border_color.right)      Dw_style_shaded_color_unref (style->border_color.right);   if (style->border_color.bottom)      Dw_style_shaded_color_unref (style->border_color.bottom);   if (style->border_color.left)      Dw_style_shaded_color_unref (style->border_color.left);   /* fixed *///   if (style->x_tooltip)//      a_Dw_tooltip_unref (style->x_tooltip);   /* fixed */    g_free (style);   styles_num--;}/* ---------------------------------------------------------------------- * *    Fonts * * ---------------------------------------------------------------------- *//* * Create the GdkFont. font->name contains one name. If try_all is * TRUE, try also standard fonts, if anything else fails. */static void Dw_style_font_realize (DwStyleFont *font, const char* charset, gboolean try_all){   char fontname[256], style_char_1 = 'r', style_char_2 = 'r';   switch (font->style) {   case DW_STYLE_FONT_STYLE_NORMAL:      style_char_1 = style_char_2 = 'r';      break;   case DW_STYLE_FONT_STYLE_ITALIC:      style_char_1 = 'i';      style_char_2 = 'o';      break;   case DW_STYLE_FONT_STYLE_OBLIQUE:      style_char_1 = 'o';      style_char_2 = 'i';      break;   }      sprintf (fontname, "*-%s-%c%cncnn-*-%d-%s",            font->name,#ifdef ENABLE_TVOUTPUT            (font->weight >= 500) ? 'd' : 'k',#else            (font->weight >= 500) ? 'b' : 'r',#endif            style_char_1, font->size,             charset?charset:"gb2312");   font->font = CreateLogFontByName (fontname);   if (font->font == NULL && font->style != DW_STYLE_FONT_STYLE_NORMAL) {      sprintf (fontname, "*-%s-%c%cncnn-*-%d-%s",               font->name,#ifdef ENABLE_TVOUTPUT               (font->weight >= 500) ? 'd' : 'k',#else               (font->weight >= 500) ? 'b' : 'r',#endif               style_char_2, font->size,                charset?charset:"gb2312");      font->font = CreateLogFontByName (fontname);   }#if 0   if (try_all) {      if (font->font == NULL) {         /* Can't load the font - substitute the default instead. */         font->font =            gdk_font_load            ("-adobe-helvetica-medium-r-normal--*-100-*-*-*-*-iso8859-1");      }      if (font->font == NULL) {         /* Try another platform-font that should be available. (iPaq) */         font->font =            gdk_font_load            ("-misc-fixed-medium-r-normal--13-120-75-75-c-80-iso8859-1");      }      if (font->font == NULL) {         /* Can't load any suitable font!  */         g_warning ("Can't load any ISO8859-1 font!?! :(");         font->font =            gdk_font_load ("-adobe-helvetica-*-*-*--*-*-*-*-*-*-*-*");      }   }#endif   if (font->font) {      SIZE ext;      SelectFont (HDC_SCREEN, font->font);      GetTextExtent (HDC_SCREEN, " ", 1, &ext);      font->space_width = ext.cx;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -