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

📄 dw_style.c

📁 嵌入式下基于MiniGUI的Web Browser
💻 C
📖 第 1 页 / 共 3 页
字号:
      font->x_height = ext.cy;   }}/* * Used for the font_table hash table. */static gint Dw_style_font_equal (gconstpointer v1, gconstpointer v2){   const DwStyleFont *font1 = (DwStyleFont*) v1, *font2 = (DwStyleFont*) v2;   return (font1->size == font2->size &&           font1->weight == font2->weight &&           font1->style == font2->style &&           strcmp (font1->name, font2->name) == 0);}/* * Used for the font_table hash table. */static guint Dw_style_font_hash (gconstpointer key){   const DwStyleFont *font = (DwStyleFont*) key;   guint h;   h = g_str_hash (font->name);   h = (h << 5) - h + font->size;   h = (h << 5) - h + font->weight;   h = (h << 5) - h + font->style;   return h;}/* * Returns a new or already existing font. This function is only used * internally, and called by a_Dw_style_font_new and * a_Dw_style_font_new_from_list. * * Note that the reference counter is not increased/set to zero, it * will be increased by a_Dw_style_new. If 'try_all' is TRUE, try also * standard fonts, if anything else fails. */static DwStyleFont* Dw_style_font_new_internal (DwStyleFont *font_attrs,                                                const char* charset, gboolean try_all){   DwStyleFont *font;   g_return_val_if_fail (font_attrs->name != NULL, NULL);   if ((font = g_hash_table_lookup (fonts_table, font_attrs))) {      return font;   } else {      font = g_new (DwStyleFont, 1);      font->size = font_attrs->size;      font->weight = font_attrs->weight;      font->style = font_attrs->style;      font->name = g_strdup (font_attrs->name);      font->ref_count = 0;      Dw_style_font_realize (font, charset, try_all);      if (font->font) {         g_hash_table_insert (fonts_table, font, font);         return font;      } else {         g_free (font->name);         g_free (font);         return NULL;      }   }}/* * Return a new or already existing font, with one name in * font_attrs->name. See also Dw_style_font_new_internal. */DwStyleFont* a_Dw_style_font_new (DwStyleFont *font_attrs, const char* charset){   DwStyleFont *font;   font = Dw_style_font_new_internal (font_attrs, charset, TRUE);   if (font == NULL)      g_error ("Could not find any font.");   return font;}/* * Return a new or already existing font, with font_attrs->name * containing a comma separated list of names. See also * Dw_style_font_new_internal. */DwStyleFont* a_Dw_style_font_new_from_list (DwStyleFont *font_attrs,                                            gchar *default_family, const char* charset){   DwStyleFont *font = NULL, font_attrs2;   char *comma, *list, *current;   font_attrs2 = *font_attrs;   current = list = g_strdup (font_attrs->name);   while (current && (font == NULL)) {      comma = strchr (current, ',');      if (comma) *comma = 0;      font_attrs2.name = current;      font = Dw_style_font_new_internal (&font_attrs2, charset, FALSE);      if (font)         break;      if (comma) {         current = comma + 1;         while (isspace (*current)) current++;      } else         current = NULL;   }   g_free (list);   if (font == NULL) {      font_attrs2.name = default_family;      font = Dw_style_font_new_internal (&font_attrs2, charset, TRUE);   }   if (font == NULL)      g_error ("Could not find any font.");   return font;}/* * Remove a font (called when ref_count == 0). */static void Dw_style_font_remove (DwStyleFont *font){   g_hash_table_remove (fonts_table, font);   g_free (font->name);#if 0   gdk_font_unref (font->font);#else   DestroyLogFont (font->font);#endif   g_free (font);}/* ---------------------------------------------------------------------- * *    Colors * * ---------------------------------------------------------------------- *//* * Copied from gtkstyle.c. * Convert RGB into HLS. */static void Dw_style_rgb_to_hls (gdouble *r,                                 gdouble *g,                                 gdouble *b){   gdouble min;   gdouble max;   gdouble red;   gdouble green;   gdouble blue;   gdouble h, l, s;   gdouble delta;   red = *r;   green = *g;   blue = *b;   if (red > green) {      if (red > blue)         max = red;      else         max = blue;      if (green < blue)         min = green;      else         min = blue;   } else {      if (green > blue)         max = green;      else         max = blue;      if (red < blue)         min = red;      else         min = blue;   }   l = (max + min) / 2;   s = 0;   h = 0;   if (max != min) {      if (l <= 0.5)         s = (max - min) / (max + min);      else         s = (max - min) / (2 - max - min);      delta = max -min;      if (red == max)         h = (green - blue) / delta;      else if (green == max)         h = 2 + (blue - red) / delta;      else if (blue == max)         h = 4 + (red - green) / delta;      h *= 60;      if (h < 0.0)         h += 360;   }   *r = h;   *g = l;   *b = s;}/* * Copied from gtkstyle.c. * Convert HLS into RGB. */static void Dw_style_hls_to_rgb (gdouble *h,                                 gdouble *l,                                 gdouble *s){   gdouble hue;   gdouble lightness;   gdouble saturation;   gdouble m1, m2;   gdouble r, g, b;   lightness = *l;   saturation = *s;   if (lightness <= 0.5)      m2 = lightness * (1 + saturation);   else      m2 = lightness + saturation - lightness * saturation;   m1 = 2 * lightness - m2;   if (saturation == 0) {      *h = lightness;      *l = lightness;      *s = lightness;   } else {      hue = *h + 120;      while (hue > 360)         hue -= 360;      while (hue < 0)         hue += 360;      if (hue < 60)            r = m1 + (m2 - m1) * hue / 60;      else if (hue < 180)         r = m2;      else if (hue < 240)         r = m1 + (m2 - m1) * (240 - hue) / 60;      else         r = m1;      hue = *h;      while (hue > 360)         hue -= 360;      while (hue < 0)         hue += 360;      if (hue < 60)         g = m1 + (m2 - m1) * hue / 60;      else if (hue < 180)         g = m2;      else if (hue < 240)         g = m1 + (m2 - m1) * (240 - hue) / 60;      else         g = m1;      hue = *h - 120;      while (hue > 360)         hue -= 360;      while (hue < 0)         hue += 360;      if (hue < 60)         b = m1 + (m2 - m1) * hue / 60;      else if (hue < 180)         b = m2;      else if (hue < 240)         b = m1 + (m2 - m1) * (240 - hue) / 60;      else         b = m1;      *h = r;      *l = g;      *s = b;   }}/* * d is a factor the color is multiplied with before, this is needed * for shaded colors. */static void Dw_style_color_create (gint color_val,                                   RGB *color,                                   gint d){   gint red, green, blue;   gdouble hue, lightness, saturation;   red = (color_val >> 16) & 255;   green = (color_val >> 8) & 255;   blue = color_val & 255;   if (d) {      hue = (gdouble)red / 255;      lightness = (gdouble)green / 255;      saturation = (gdouble)blue / 255;#if 0      DEBUG_MSG (1, "Shaded by %1.3g: (%1.3g, %1.3g, %1.3g) -> ",                 d, hue, lightness, saturation);#endif      Dw_style_rgb_to_hls (&hue, &lightness, &saturation);      if (lightness > 0.8) {         if (d > 0)            lightness -= 0.2;         else            lightness -= 0.4;      } else if (lightness < 0.2) {         if (d > 0)            lightness += 0.4;         else            lightness += 0.2;      } else         lightness += d * 0.2;      Dw_style_hls_to_rgb (&hue, &lightness, &saturation);      DEBUG_MSG (1, "(%1.3g, %1.3g, %1.3g)\n", hue, lightness, saturation);      red = hue * 255;      green = lightness * 255;      blue = saturation * 255;   }   blue |= blue << 8;   red |= red << 8;   green |= green << 8;/* infinite *///   gdk_color_alloc (gdk_window_get_colormap (window), color);////   *gc = gdk_gc_new (window);//   gdk_gc_set_foreground (*gc, color);/* infinite */   color->r = red;   color->g = green;

⌨️ 快捷键说明

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