コード例 #1
0
ファイル: font.c プロジェクト: miurahr/wine
/*******************************************************************************
 * GdipGetFontHeightGivenDPI [GDIPLUS.@]
 * PARAMS
 *  font        [I] Font to retrieve DPI from
 *  dpi         [I] DPI to assume
 *  height      [O] Return value
 *
 * RETURNS
 *  SUCCESS: Ok
 *  FAILURE: InvalidParameter if font or height is NULL
 *
 * NOTES
 *  According to MSDN, the result is (lineSpacing)*(fontSize / emHeight)*dpi
 *  (for anything other than unit Pixel)
 */
GpStatus WINGDIPAPI GdipGetFontHeightGivenDPI(GDIPCONST GpFont *font, REAL dpi, REAL *height)
{
    GpStatus stat;
    INT style;
    UINT16 line_spacing, em_height;
    REAL font_size;

    if (!font || !height) return InvalidParameter;

    TRACE("%p (%s), %f, %p\n", font,
            debugstr_w(font->family->FamilyName), dpi, height);

    font_size = units_to_pixels(get_font_size(font), font->unit, dpi);
    style = get_font_style(font);
    stat = GdipGetLineSpacing(font->family, style, &line_spacing);
    if (stat != Ok) return stat;
    stat = GdipGetEmHeight(font->family, style, &em_height);
    if (stat != Ok) return stat;

    *height = (REAL)line_spacing * font_size / (REAL)em_height;

    TRACE("%s,%d => %f\n",
          debugstr_w(font->family->FamilyName), font->otm.otmTextMetrics.tmHeight, *height);

    return Ok;
}
コード例 #2
0
ファイル: el_table.cpp プロジェクト: CarterTsai/litehtml
void litehtml::el_table::parse_styles(bool is_reparse)
{
	html_tag::parse_styles(is_reparse);

	m_border_collapse = (border_collapse) value_index(get_style_property(_t("border-collapse"), true, _t("separate")), border_collapse_strings, border_collapse_separate);

	if(m_border_collapse == border_collapse_separate)
	{
		m_css_border_spacing_x.fromString(get_style_property(_t("-litehtml-border-spacing-x"), true, _t("0px")));
		m_css_border_spacing_y.fromString(get_style_property(_t("-litehtml-border-spacing-y"), true, _t("0px")));

		int fntsz = get_font_size();
		document::ptr doc = get_document();
		m_border_spacing_x = doc->cvt_units(m_css_border_spacing_x, fntsz);
		m_border_spacing_y = doc->cvt_units(m_css_border_spacing_y, fntsz);
	} else
	{
		m_border_spacing_x	= 0;
		m_border_spacing_y	= 0;
		m_padding.bottom	= 0;
		m_padding.top		= 0;
		m_padding.left		= 0;
		m_padding.right		= 0;
		m_css_padding.bottom.set_value(0, css_units_px);
		m_css_padding.top.set_value(0, css_units_px);
		m_css_padding.left.set_value(0, css_units_px);
		m_css_padding.right.set_value(0, css_units_px);
	}
}
コード例 #3
0
ファイル: text_entry.cpp プロジェクト: jseward/solar
	int text_entry::get_cursor_caret_pos(const point& cursor_pos) const {
		int cursor_caret_pos = _visible_pos;

		int text_area_left = get_text_area().get_left();
		if (cursor_pos._x >= text_area_left) {
			
			auto& font = get_font();
			float font_size = get_font_size();

			std::wstring visible_text = _text;
			raw_text_to_visible_text(visible_text);
			
			int text_length = uint_to_int(visible_text.length());
			while (cursor_caret_pos < text_length) {
				float width_a = font.get_text_width(font_size, visible_text.c_str(), _visible_pos, cursor_caret_pos - _visible_pos);
				float width_b = font.get_text_width(font_size, visible_text.c_str(), _visible_pos, cursor_caret_pos - _visible_pos + 1);
				float width_extra = (width_b - width_a) / 2.f;
				if (cursor_pos._x < (int_to_float(text_area_left) + width_a + width_extra)) {
					break;
				}
				cursor_caret_pos++;
			}
		}

	 	return cursor_caret_pos;
	}
コード例 #4
0
ファイル: configfile.c プロジェクト: BartMassey/gnome-inform7
/* Get the current font as a PangoFontDescription.
Must be freed with pango_font_description_free. */
PangoFontDescription *
get_font_description(void)
{
	PangoFontDescription *font = get_font_family();
	pango_font_description_set_size(font, get_font_size(font));
	return font;
}
コード例 #5
0
ファイル: element.cpp プロジェクト: bigfatbrowncat/litehtml
int litehtml::element::calc_width(int defVal) const
{
	css_length w = get_css_width();
	if(w.is_predefined())
	{
		return defVal;
	}
	if(w.units() == css_units_percentage)
	{
		if(!m_parent)
		{
			position client_pos;
			m_doc->container()->get_client_rect(client_pos);
			return w.calc_percent(client_pos.width);
		} else
		{
			int pw = m_parent->calc_width(defVal);
			if (is_body())
			{
				pw -= content_margins_width();
			}
			return w.calc_percent(pw);
		}
	}
	return 	m_doc->cvt_units(w, get_font_size());
}
コード例 #6
0
ファイル: menu.cpp プロジェクト: oys0317/opensanguo
SDL_Rect menu::style::item_size(const std::string& item) const {
	SDL_Rect res = {0,0,0,0};
	std::vector<std::string> img_text_items = utils::split(item, IMG_TEXT_SEPARATOR, utils::REMOVE_EMPTY);
	for (std::vector<std::string>::const_iterator it = img_text_items.begin();
		 it != img_text_items.end(); it++) {
		if (res.w > 0 || res.h > 0) {
			// Not the first item, add the spacing.
			res.w += 5;
		}
		const std::string str = *it;
		if (!str.empty() && str[0] == IMAGE_PREFIX) {
			const std::string image_name(str.begin()+1,str.end());
			surface const img = get_item_image(image_name);
			if(img != NULL) {
				res.w += img->w;
				res.h = std::max<int>(img->h, res.h);
			}
		} else {
			const SDL_Rect area = {0,0,10000,10000};
			const SDL_Rect font_size =
				font::draw_text(NULL,area,get_font_size(),font::NORMAL_COLOUR,str,0,0);
			res.w += font_size.w;
			res.h = std::max<int>(font_size.h, res.h);
		}
	}
	return res;
}
コード例 #7
0
	static void 
	font_size_changed (GtkAdjustment *adjustment,
		               MucharmapMiniFontSelection *fontsel)
	{
	  int new_size;

	  new_size = gtk_adjustment_get_value (adjustment);
	  if (new_size != get_font_size (fontsel))
		set_font_size (fontsel, new_size);
	}
コード例 #8
0
ファイル: font.c プロジェクト: miurahr/wine
/******************************************************************************
 * GdipGetFontSize [GDIPLUS.@]
 *
 * Returns the size of the font in Units
 *
 * PARAMS
 *  *font       [I] The font to retrieve size from
 *  *size       [O] Pointer to hold retrieved value
 *
 * RETURNS
 *  SUCCESS: Ok
 *  FAILURE: InvalidParameter (font or size was NULL)
 *
 * NOTES
 *  Size returned is actually emSize -- not internal size used for drawing.
 */
GpStatus WINGDIPAPI GdipGetFontSize(GpFont *font, REAL *size)
{
    TRACE("(%p, %p)\n", font, size);

    if (!(font && size)) return InvalidParameter;

    *size = get_font_size(font);
    TRACE("%s,%d => %f\n", debugstr_w(font->family->FamilyName), font->otm.otmTextMetrics.tmHeight, *size);

    return Ok;
}
コード例 #9
0
static void
find_good_window_size_from_style (GtkWidget *widget,
				  int       *width,
				  int       *height)
{
	int font_size;

	font_size = get_font_size (widget);
	*width = font_size * FILE_LIST_CHARS;
	*height = font_size * FILE_LIST_LINES;
}
コード例 #10
0
ファイル: renderer.cpp プロジェクト: oviano/gdi2ft
bool GDI2FT_RENDERER::generate_glyph_run( bool is_glyph_index, LPCWSTR lpString, UINT c, GDI2FT_GLPYH_RUN& new_glyph_run, bool request_outline )
/* --------------------------------------------------------------------------------
-------------------------------------------------------------------------------- */
{
	wstring font_face = reinterpret_cast<const wchar_t *>( reinterpret_cast<const BYTE *>( context->outline_metrics ) + reinterpret_cast<const UINT>( context->outline_metrics->otmpFaceName ) );
	long font_id = font_store.register_font( context->hdc, font_face.c_str() );
	if( font_id < 0 )
		return false;

	const GDI2FT_FONT_INFO *font_info = font_store.lookup_font( font_id );
	const GDI2FT_OS2_METRICS *os2_metrics = &font_info->os2_metrics;

	FTC_ScalerRec scaler = {};
	scaler.face_id = reinterpret_cast<FTC_FaceID>( font_id );
	scaler.pixel = 1;
	get_font_size( context->outline_metrics, ( context->log_font.lfWidth == 0 ? 0 : os2_metrics->get_xAvgCharWidth() ), scaler.width, scaler.height );

	FT_F26Dot6 embolden = 0;
	if( context->log_font.lfWeight != FW_DONTCARE )
		embolden = get_embolden( os2_metrics->get_usWeightClass(), static_cast<FT_UShort>( context->log_font.lfWeight ) );

	if( is_glyph_index )
	{
		for( UINT i = 0; i < c; i ++ )
		{
			const FT_Glyph new_glyph = generate_bitmap_glyph( lpString[ i ], &scaler, embolden, os2_metrics->is_italic(), request_outline );
			RECT ctrl_box = {}, black_box = {};

			if( new_glyph == NULL )
			{
				if( request_outline )
					return false;
			}
			else if( i > 0 && !request_outline )
			{
				FT_Size size;
				FTC_Manager_LookupSize( ft_cache_man, &scaler, &size );

				FT_Vector delta;
				FT_Get_Kerning( size->face, lpString[ i - 1 ], lpString[ i ], FT_KERNING_DEFAULT, &delta );

				ctrl_box.left = delta.x >> 6;
				ctrl_box.right = ctrl_box.left;
			}
			
			new_glyph_run.glyphs.push_back( new_glyph );
			new_glyph_run.ctrl_boxes.push_back( ctrl_box );
			new_glyph_run.black_boxes.push_back( black_box );
		}
	}
コード例 #11
0
ファイル: fontset.c プロジェクト: dkogan/notion
XFontSet de_create_font_kludged(const char *fontname)
{
    XFontSet fs = NULL;
#ifndef CF_NO_FONTSET_KLUDGE
    char *pattern2=NULL;
    char weight[CF_FONT_ELEMENT_SIZE], slant[CF_FONT_ELEMENT_SIZE];
    int pixel_size=0;

    LOG(DEBUG, FONT, "Doing the fontset_kludge with fontname %s.", fontname);

    get_font_element(fontname, weight, CF_FONT_ELEMENT_SIZE,
                     "-medium-", "-bold-", "-demibold-", "-regular-", NULL);
    get_font_element(fontname, slant, CF_FONT_ELEMENT_SIZE,
                     "-r-", "-i-", "-o-", "-ri-", "-ro-", NULL);
    get_font_size(fontname, &pixel_size);

    if(!strcmp(weight, "*"))
        strncpy(weight, "medium", CF_FONT_ELEMENT_SIZE);
    if(!strcmp(slant, "*"))
        strncpy(slant, "r", CF_FONT_ELEMENT_SIZE);
    if(pixel_size<3)
        pixel_size=3;
    else if(pixel_size>97)
        pixel_size=97;

    if(ioncore_g.enc_utf8){
        libtu_asprintf(&pattern2,
                       "%s,"
                       "-misc-fixed-%s-%s-*-*-%d-*-*-*-*-*-*-*,"
                       "-misc-fixed-*-*-*-*-%d-*-*-*-*-*-*-*",
                       fontname, weight, slant, pixel_size, pixel_size);
    }else{
        libtu_asprintf(&pattern2,
                       "%s,"
                       "-*-*-%s-%s-*-*-%d-*-*-*-*-*-*-*,"
                       "-*-*-*-*-*-*-%d-*-*-*-*-*-*-*",
                       fontname, weight, slant, pixel_size, pixel_size);
    }

    if(pattern2!=NULL){
        LOG(DEBUG, FONT, "no_fontset_kludge resulted in fontname %s", pattern2);

        fs = de_create_font_in_current_locale(pattern2);

        free(pattern2);
    }

#endif
    return fs;
}
コード例 #12
0
ファイル: font.c プロジェクト: dylanahsmith/wine
/*******************************************************************************
 * GdipGetFontHeightGivenDPI [GDIPLUS.@]
 * PARAMS
 *  font        [I] Font to retrieve DPI from
 *  dpi         [I] DPI to assume
 *  height      [O] Return value
 *
 * RETURNS
 *  SUCCESS: Ok
 *  FAILURE: InvalidParameter if font or height is NULL
 *
 * NOTES
 *  According to MSDN, the result is (lineSpacing)*(fontSize / emHeight)*dpi
 *  (for anything other than unit Pixel)
 */
GpStatus WINGDIPAPI GdipGetFontHeightGivenDPI(GDIPCONST GpFont *font, REAL dpi, REAL *height)
{
    GpStatus stat;
    INT style;
    UINT16 line_spacing, em_height;
    REAL font_height, font_size;

    if (!font || !height) return InvalidParameter;

    TRACE("%p (%s), %f, %p\n", font,
            debugstr_w(font->family->FamilyName), dpi, height);

    font_size = get_font_size(font);
    style = get_font_style(font);
    stat = GdipGetLineSpacing(font->family, style, &line_spacing);
    if (stat != Ok) return stat;
    stat = GdipGetEmHeight(font->family, style, &em_height);
    if (stat != Ok) return stat;

    font_height = (REAL)line_spacing * font_size / (REAL)em_height;

    switch (font->unit)
    {
        case UnitPixel:
        case UnitWorld:
            *height = font_height;
            break;
        case UnitPoint:
            *height = font_height * dpi * inch_per_point;
            break;
        case UnitInch:
            *height = font_height * dpi;
            break;
        case UnitDocument:
            *height = font_height * (dpi / 300.0);
            break;
        case UnitMillimeter:
            *height = font_height * (dpi / mm_per_inch);
            break;
        default:
            FIXME("Unhandled unit type: %d\n", font->unit);
            return NotImplemented;
    }

    TRACE("%s,%d(unit %d) => %f\n",
          debugstr_w(font->family->FamilyName), font->otm.otmTextMetrics.tmHeight, font->unit, *height);

    return Ok;
}
コード例 #13
0
ファイル: base-io.c プロジェクト: walls-of-doom/walls-of-doom
/**
 * Initializes the global fonts.
 */
static Code initialize_fonts(void) {
  char log_buffer[MAXIMUM_STRING_SIZE];
  Font *font = NULL;
  if (global_monospaced_font != NULL) {
    return CODE_OK;
  }
  /* We try to open the font if we need to initialize. */
  font = TTF_OpenFont(MONOSPACED_FONT_PATH, get_font_size());
  /* If it failed, we log an error. */
  if (font == NULL) {
    sprintf(log_buffer, "TTF font opening error: %s.", SDL_GetError());
    log_message(log_buffer);
    return CODE_ERROR;
  }
  global_monospaced_font = font;

  return CODE_OK;
}
コード例 #14
0
	void
	mucharmap_mini_font_selection_change_font_size (MucharmapMiniFontSelection *fontsel,
		                                            float factor)
	{
	  int size, new_size;

	  g_return_if_fail (factor > 0.0f);

	  size = get_font_size (fontsel);
	  new_size = (float) size * factor;

	  if (factor > 1.0f)
		new_size = MAX (new_size, size + 1);
	  else if (factor < 1.0f)
		new_size = MIN (new_size, size - 1);

	  set_font_size (fontsel, new_size);
	}
コード例 #15
0
ファイル: font.hpp プロジェクト: hirakuni45/RX
		//-----------------------------------------------------------------//
		vtx::spos get_text_size(const char* text, bool prop = false) noexcept
		{
			char cha;
			vtx::spos sz(0);
			int16_t x = 0;
			while((cha = *text++) != 0) {
				if(cha == '\n') {
					if(sz.x < x) sz.x = x;
					x = 0;
					sz.y += height;
				} else {
					// 画面外を指定してサイズだけ取得
					x += get_font_size(cha, prop);
				}
			}
			if(sz.x < x) sz.x = x;
			if(sz.y == 0) sz.y = height;
			else if(x > 0) sz.y += height;
			return sz;
		}
コード例 #16
0
static void
fr_file_selector_dialog_realize (GtkWidget *widget)
{
	FrFileSelectorDialog *self;
	GIcon                *icon;
	int                   sidebar_size;

	GTK_WIDGET_CLASS (fr_file_selector_dialog_parent_class)->realize (widget);

	self = FR_FILE_SELECTOR_DIALOG (widget);

	self->priv->icon_cache = gth_icon_cache_new_for_widget (GTK_WIDGET (self), GTK_ICON_SIZE_MENU);
	icon = g_content_type_get_icon ("text/plain");
	gth_icon_cache_set_fallback (self->priv->icon_cache, icon);
	g_object_unref (icon);

	_fr_file_selector_dialog_update_size (self);

	sidebar_size = g_settings_get_int (self->priv->settings, PREF_FILE_SELECTOR_SIDEBAR_SIZE);
	if (sidebar_size <= 0)
		sidebar_size = get_font_size (widget) * SIDEBAR_CHARS;
		gtk_paned_set_position (GTK_PANED (GET_WIDGET ("main_paned")), sidebar_size);
}
コード例 #17
0
ファイル: element.cpp プロジェクト: bigfatbrowncat/litehtml
bool litehtml::element::get_predefined_height(int& p_height) const
{
	css_length h = get_css_height();
	if(h.is_predefined())
	{
		p_height = m_pos.height;
		return false;
	}
	if(h.units() == css_units_percentage)
	{
		if(!m_parent)
		{
			position client_pos;
			m_doc->container()->get_client_rect(client_pos);
			p_height = h.calc_percent(client_pos.height);
			return true;
		} else
		{
			int ph = 0;
			if(m_parent->get_predefined_height(ph))
			{
				p_height = h.calc_percent(ph);
				if (is_body())
				{
					p_height -= content_margins_height();
				}
				return true;
			} else
			{
				p_height = m_pos.height;
				return false;
			}
		}
	}
	p_height = m_doc->cvt_units(h, get_font_size());
	return true;
}
コード例 #18
0
static void html_eval_tag(XMLState *s, CSSBox *box)
{
    const char *value;
    CSSProperty *first_prop, **last_prop;
    QEColor color;
    int width, height, val, type;
    int border, padding;
    CSSPropertyValue arg;
    CSSPropertyValue args[2];

    first_prop = NULL;
    last_prop = &first_prop;
    switch (box->tag) {
    case CSS_ID_img:
    parse_img:
        box->content_type = CSS_CONTENT_TYPE_IMAGE;
        box->u.image.content_alt = NULL;
        /* set alt content */
        value = css_attr_str(box, CSS_ID_alt);
        if (!value) {
            /* if no alt, display the name of the image */
            value = css_attr_str(box, CSS_ID_src);
            if (value)
                value = basename(value);
        }
        if (value && value[0] != '\0') {
            arg.type = CSS_VALUE_STRING;
            arg.u.str = strdup(value);
            css_add_prop(&last_prop, CSS_content_alt, &arg);
        }
        
        width = css_attr_int(box, CSS_ID_width, 0);
        if (width <= 0)
            width = DEFAULT_IMG_WIDTH;
        height = css_attr_int(box, CSS_ID_height, 0);
        if (height <= 0)
            height = DEFAULT_IMG_HEIGHT;

        css_add_prop_unit(&last_prop, CSS_width, 
                          CSS_UNIT_PIXEL, width);
        css_add_prop_unit(&last_prop, CSS_height, 
                          CSS_UNIT_PIXEL, height);

        /* border */
        val = css_attr_int(box, CSS_ID_border, -1);
        if (val >= 0) {
            css_add_prop_unit(&last_prop, CSS_border_left_width,
                              CSS_UNIT_PIXEL, val);
            css_add_prop_unit(&last_prop, CSS_border_right_width,
                              CSS_UNIT_PIXEL, val);
            css_add_prop_unit(&last_prop, CSS_border_top_width,
                              CSS_UNIT_PIXEL, val);
            css_add_prop_unit(&last_prop, CSS_border_bottom_width,
                              CSS_UNIT_PIXEL, val);

            css_add_prop_int(&last_prop, CSS_border_left_style,
                             CSS_BORDER_STYLE_SOLID);
            css_add_prop_int(&last_prop, CSS_border_right_style,
                             CSS_BORDER_STYLE_SOLID);
            css_add_prop_int(&last_prop, CSS_border_top_style,
                             CSS_BORDER_STYLE_SOLID);
            css_add_prop_int(&last_prop, CSS_border_bottom_style,
                             CSS_BORDER_STYLE_SOLID);
        }
        /* margins */
        val = css_attr_int(box, CSS_ID_hspace, -1);
        if (val >= 0) {
            css_add_prop_unit(&last_prop, CSS_margin_left,
                              CSS_UNIT_PIXEL, val);
            css_add_prop_unit(&last_prop, CSS_margin_right,
                              CSS_UNIT_PIXEL, val);
        }
        val = css_attr_int(box, CSS_ID_vspace, -1);
        if (val >= 0) {
            css_add_prop_unit(&last_prop, CSS_margin_top, 
                              CSS_UNIT_PIXEL, val);
            css_add_prop_unit(&last_prop, CSS_margin_bottom,
                              CSS_UNIT_PIXEL, val);
        }
        break;
    case CSS_ID_body:
        value = css_attr_str(box, CSS_ID_text);
        if (value && !css_get_color(&color, value)) {
            css_add_prop_int(&last_prop, CSS_color, color);
        }
        /* we handle link by adding a new stylesheet entry */
        value = css_attr_str(box, CSS_ID_link);
        if (value && !css_get_color(&color, value)) {
            CSSStyleSheetEntry *e;
            CSSSimpleSelector ss1, *ss = &ss1;
            CSSProperty **last_prop;
            CSSStyleSheetAttributeEntry **plast_attr;

            /* specific to <a href="xxx"> tag */
            memset(ss, 0, sizeof(CSSSimpleSelector));
            ss->tag = CSS_ID_a;
            plast_attr = &ss->attrs;
            add_attribute(&plast_attr, CSS_ID_href, CSS_ATTR_OP_SET, "");
                          
            e = add_style_entry(s->style_sheet, ss, CSS_MEDIA_ALL);

            /* add color property */
            last_prop = &e->props;
            css_add_prop_int(&last_prop, CSS_color, color);
        }
        break;
    case CSS_ID_font:
    case CSS_ID_basefont:
        /* size */
        value = css_attr_str(box, CSS_ID_size);
        if (value) {
            val = strtol(value, NULL, 10);
            if (value[0] == '+' || value[0] == '-') {
                /* relative size */
                val += s->base_font;
            }
            if (val < 1)
                val = 1;
            else if (val > 7)
                val = 7;
            if (box->tag == CSS_ID_basefont)
                s->base_font = val;
            /* XXX: incorrect for basefont */
            css_add_prop_unit(&last_prop, CSS_font_size, 
                              CSS_UNIT_IN, get_font_size(val - 1));
        }
            
        /* color */
        value = css_attr_str(box, CSS_ID_color);
        if (value && !css_get_color(&color, value)) {
            css_add_prop_int(&last_prop, CSS_color, color);
        }
        break;
    case CSS_ID_br:
        value = css_attr_strlower(box, CSS_ID_clear);
        if (value) {
            val = css_get_enum(value, "none,left,right,all");
            if (val >= 0) {
                css_add_prop_int(&last_prop, CSS_clear, val + CSS_CLEAR_NONE);
            }
        }
        break;
    case CSS_ID_table:
        val = css_attr_int(box, CSS_ID_width, -1);
        if (val >= 0) {
            css_add_prop_unit(&last_prop, CSS_width,
                              CSS_UNIT_PIXEL, val);
        }
        border = css_attr_int(box, CSS_ID_border, -1);
        if (border >= 0) {
            css_add_prop_unit(&last_prop, CSS_border_left_width, 
                              CSS_UNIT_PIXEL, border);
            css_add_prop_unit(&last_prop, CSS_border_right_width,
                              CSS_UNIT_PIXEL, border);
            css_add_prop_unit(&last_prop, CSS_border_top_width,
                              CSS_UNIT_PIXEL, border);
            css_add_prop_unit(&last_prop, CSS_border_bottom_width,
                              CSS_UNIT_PIXEL, border);
            css_add_prop_int(&last_prop, CSS_border_left_style,
                             CSS_BORDER_STYLE_GROOVE);
            css_add_prop_int(&last_prop, CSS_border_right_style,
                             CSS_BORDER_STYLE_GROOVE);
            css_add_prop_int(&last_prop, CSS_border_top_style,
                             CSS_BORDER_STYLE_GROOVE);
            css_add_prop_int(&last_prop, CSS_border_bottom_style,
                             CSS_BORDER_STYLE_GROOVE);
            /* cell have a border of 1 pixel width */
            if (border > 1)
                border = 1;
        }
        val = css_attr_int(box, CSS_ID_cellspacing, -1);
        if (val >= 0) {
            css_add_prop_unit(&last_prop, CSS_border_spacing_horizontal, 
                              CSS_UNIT_PIXEL, val);
            css_add_prop_unit(&last_prop, CSS_border_spacing_vertical,
                              CSS_UNIT_PIXEL, val);
        }
        padding = css_attr_int(box, CSS_ID_cellpadding, -1);
        /* apply border styles to each cell (cannot be done exactly by
           CSS) */
        if (border >= 1 || padding >= 1)
            html_table_borders(box, border, padding);
        break;

    case CSS_ID_col:
    case CSS_ID_colgroup:
        val = css_attr_int(box, CSS_ID_width, -1);
        if (val >= 0) {
            css_add_prop_unit(&last_prop, CSS_width, CSS_UNIT_PIXEL, val);
        }
        break;
    case CSS_ID_td:
        val = css_attr_int(box, CSS_ID_width, -1);
        if (val >= 0) {
            css_add_prop_unit(&last_prop, CSS_width, CSS_UNIT_PIXEL, val);
        }
        val = css_attr_int(box, CSS_ID_height, -1);
        if (val >= 0) {
            css_add_prop_unit(&last_prop, CSS_height, CSS_UNIT_PIXEL, val);
        }
        break;

    case CSS_ID_ol:
    case CSS_ID_li:
        /* NOTE: case is important */
        /* XXX: currently cannot propagate for LI tag */
        value = css_attr_str(box, CSS_ID_type);
        if (value) {
            val = css_get_enum(value, "1,a,A,i,I");
            if (val >= 0) {
                val += CSS_LIST_STYLE_TYPE_DECIMAL;
                css_add_prop_int(&last_prop, CSS_list_style_type, val);
            }
        }
        /* XXX: add value, but needs a css extension */
        if (box->tag == CSS_ID_ol) 
            val = CSS_ID_start;
        else
            val = CSS_ID_value;
        /* NOTE: only works with digits */
        val = css_attr_int(box, val, 0);
        if (val > 0) {
            args[0].type = CSS_VALUE_IDENT;
            args[0].u.val = CSS_ID_list_item;
            args[1].type = CSS_VALUE_INTEGER;
            args[1].u.val = val - 1; /* currently needs minus 1 */
            css_add_prop_values(&last_prop, CSS_counter_reset, 2, args);
        }
        break;
        /* controls */
    case CSS_ID_button:
        type = CSS_ID_submit;
        value = css_attr_strlower(box, CSS_ID_type);
        if (value)
            type = css_new_ident(value);
        if (type != CSS_ID_button && type != CSS_ID_reset)
            type = CSS_ID_submit;
        goto parse_input;
    case CSS_ID_input:
        type = CSS_ID_text;
        value = css_attr_strlower(box, CSS_ID_type);
        if (value) {
            type = css_new_ident(value);
        } else {
            CSSAttribute *attr;
            /* NOTE: we add an attribute for css rules */
            attr = box_new_attr(CSS_ID_type, "text");
            if (attr) {
                attr->next = box->attrs;
                box->attrs = attr;
            }
        }
            
    parse_input:
        if (type == CSS_ID_image)
            goto parse_img;
        if (type == CSS_ID_button ||
            type == CSS_ID_reset ||
            type == CSS_ID_submit ||
            type == CSS_ID_text ||
            type == CSS_ID_password ||
            type == CSS_ID_file) {
            /* put text inside the box (XXX: use attr() in content
               attribute ? */
            value = css_attr_str(box, CSS_ID_value);
            if (value) {
                css_set_text_string(box, value);
            }
        }
        /* size */
        if (type == CSS_ID_text ||
            type == CSS_ID_password) {
            val = css_attr_int(box, CSS_ID_size, 10);
            css_add_prop_unit(&last_prop, CSS_width,
                              CSS_UNIT_EM, val << CSS_LENGTH_FRAC_BITS);
        }
        break;
    case CSS_ID_textarea:
        val = css_attr_int(box, CSS_ID_cols, 10);
        if (val < 1)
            val = 1;
        css_add_prop_unit(&last_prop, CSS_width, 
                          CSS_UNIT_EM, val << CSS_LENGTH_FRAC_BITS);

        val = css_attr_int(box, CSS_ID_rows, 1);
        if (val < 1)
            val = 1;
        css_add_prop_unit(&last_prop, CSS_height, 
                          CSS_UNIT_EM, val << CSS_LENGTH_FRAC_BITS);
        break;
    case CSS_ID_select:
        val = css_attr_int(box, CSS_ID_size, 1);
        if (val < 1)
            val = 1;
        css_add_prop_unit(&last_prop, CSS_height, 
                          CSS_UNIT_EM, val << CSS_LENGTH_FRAC_BITS);
        break;
    default:
        break;
    }

    /* generic attributes */
    value = css_attr_str(box, CSS_ID_bgcolor);
    if (value && !css_get_color(&color, value)) {
        css_add_prop_int(&last_prop, CSS_background_color, color);
    }
    value = css_attr_strlower(box, CSS_ID_align);
    if (value) {
        switch (box->tag) {
        case CSS_ID_caption:
            /* use caption-side property for captions */
            val = css_get_enum(value, "top,bottom,left,right");
            if (val >= 0) {
                css_add_prop_int(&last_prop, CSS_caption_side, val);
            }
            break;
        case CSS_ID_img:
            /* floating images */
            val = css_get_enum(value, "left,right");
            if (val >= 0) {
                css_add_prop_int(&last_prop, CSS_float, val + CSS_FLOAT_LEFT);
            }
            break;
        case CSS_ID_table:
            val = css_get_enum(value, "left,right,center");
            if (val == CSS_TEXT_ALIGN_LEFT || val == CSS_TEXT_ALIGN_RIGHT) {
                css_add_prop_int(&last_prop, CSS_float, val + CSS_FLOAT_LEFT);
            } else if (val == CSS_TEXT_ALIGN_CENTER) {
                css_add_prop_int(&last_prop, CSS_margin_left, CSS_AUTO);
                css_add_prop_int(&last_prop, CSS_margin_right, CSS_AUTO);
            }
            break;
        default:
            val = css_get_enum(value, "left,right,center");
            if (val >= 0) {
                css_add_prop_int(&last_prop, CSS_text_align, val);
            }
            break;
        }
    }
    value = css_attr_strlower(box, CSS_ID_valign);
    if (value) {
        val = css_get_enum(value, "baseline,,,top,,middle,bottom");
        if (val >= 0) {
            css_add_prop_int(&last_prop, CSS_vertical_align, val);
        }
    }

    val = css_attr_int(box, CSS_ID_colspan, 1);
    if (val > 1) {
        css_add_prop_unit(&last_prop, CSS_column_span, CSS_VALUE_INTEGER, val);
    }
    val = css_attr_int(box, CSS_ID_rowspan, 1);
    if (val > 1) {
        css_add_prop_unit(&last_prop, CSS_row_span, CSS_VALUE_INTEGER, val);
    }

    value = css_attr_str(box, CSS_ID_style);
    if (value) {
        CSSParseState b1, *b = &b1;
        b->ptr = NULL;
        b->line_num = s->line_num; /* XXX: slightly incorrect */
        b->filename = s->filename;
        b->ignore_case = s->ignore_case;
        *last_prop = css_parse_properties(b, value);
    }
    box->properties = first_prop;
}
コード例 #19
0
ファイル: computed.c プロジェクト: JamesLinus/nui3
/**
 * Compute the absolute values of a style
 *
 * \param parent             Parent style, or NULL for tree root
 * \param style              Computed style to process
 * \param compute_font_size  Callback to calculate an absolute font-size
 * \param pw                 Private word for callback
 * \return CSS_OK on success.
 */
css_error compute_absolute_values(const css_computed_style *parent,
		css_computed_style *style,
		css_error (*compute_font_size)(void *pw, 
			const css_hint *parent, css_hint *size),
		void *pw)
{
	css_hint psize, size, ex_size;
	css_error error;

	/* Ensure font-size is absolute */
	if (parent != NULL) {
		psize.status = get_font_size(parent, 
				&psize.data.length.value, 
				&psize.data.length.unit);
	}

	size.status = get_font_size(style, 
			&size.data.length.value, 
			&size.data.length.unit);

	error = compute_font_size(pw, parent != NULL ? &psize : NULL, &size);
	if (error != CSS_OK)
		return error;

	error = set_font_size(style, size.status,
			size.data.length.value, 
			size.data.length.unit);
	if (error != CSS_OK)
		return error;

	/* Compute the size of an ex unit */
	ex_size.status = CSS_FONT_SIZE_DIMENSION;
	ex_size.data.length.value = INTTOFIX(1);
	ex_size.data.length.unit = CSS_UNIT_EX;
	error = compute_font_size(pw, &size, &ex_size);
	if (error != CSS_OK)
		return error;

	/* Convert ex size into ems */
	if (size.data.length.value != 0)
		ex_size.data.length.value = FDIV(ex_size.data.length.value, 
					size.data.length.value);
	else
		ex_size.data.length.value = 0;
	ex_size.data.length.unit = CSS_UNIT_EM;

	/* Fix up background-position */
	error = compute_absolute_length_pair(style, &ex_size.data.length, 
			get_background_position,
			set_background_position);
	if (error != CSS_OK)
		return error;

	/* Fix up border-{top,right,bottom,left}-color */
	error = compute_border_colors(style);
	if (error != CSS_OK)
		return error;

	/* Fix up border-{top,right,bottom,left}-width */
	error = compute_absolute_border_width(style, &ex_size.data.length);
	if (error != CSS_OK)
		return error;

	/* Fix up sides */
	error = compute_absolute_sides(style, &ex_size.data.length);
	if (error != CSS_OK)
		return error;

	/* Fix up height */
	error = compute_absolute_length_auto(style, &ex_size.data.length, 
			get_height, set_height);
	if (error != CSS_OK)
		return error;

	/* Fix up line-height (must be before vertical-align) */
	error = compute_absolute_line_height(style, &ex_size.data.length);
	if (error != CSS_OK)
		return error;

	/* Fix up margins */
	error = compute_absolute_margins(style, &ex_size.data.length);
	if (error != CSS_OK)
		return error;

	/* Fix up max-height */
	error = compute_absolute_length_none(style, &ex_size.data.length, 
			get_max_height, set_max_height);
	if (error != CSS_OK)
		return error;

	/* Fix up max-width */
	error = compute_absolute_length_none(style, &ex_size.data.length, 
			get_max_width, set_max_width);
	if (error != CSS_OK)
		return error;

	/* Fix up min-height */
	error = compute_absolute_length(style, &ex_size.data.length, 
			get_min_height, set_min_height);
	if (error != CSS_OK)
		return error;

	/* Fix up min-width */
	error = compute_absolute_length(style, &ex_size.data.length, 
			get_min_width, set_min_width);
	if (error != CSS_OK)
		return error;

	/* Fix up padding */
	error = compute_absolute_padding(style, &ex_size.data.length);
	if (error != CSS_OK)
		return error;

	/* Fix up text-indent */
	error = compute_absolute_length(style, &ex_size.data.length, 
			get_text_indent, set_text_indent);
	if (error != CSS_OK)
		return error;

	/* Fix up vertical-align */
	error = compute_absolute_vertical_align(style, &ex_size.data.length);
	if (error != CSS_OK)
		return error;

	/* Fix up width */
	error = compute_absolute_length_auto(style, &ex_size.data.length, 
			get_width, set_width);
	if (error != CSS_OK)
		return error;

	/* Uncommon properties */
	if (style->uncommon != NULL) {
		/* Fix up border-spacing */
		error = compute_absolute_length_pair(style,
				&ex_size.data.length,
				get_border_spacing,
				set_border_spacing);
		if (error != CSS_OK)
			return error;

		/* Fix up clip */
		error = compute_absolute_clip(style, &ex_size.data.length);
		if (error != CSS_OK)
			return error;

		/* Fix up letter-spacing */
		error = compute_absolute_length_normal(style,
				&ex_size.data.length,
				get_letter_spacing, 
				set_letter_spacing);
		if (error != CSS_OK)
			return error;

		/* Fix up outline-width */
		error = compute_absolute_border_side_width(style, 
				&ex_size.data.length, 
				get_outline_width, 
				set_outline_width);
		if (error != CSS_OK)
			return error;

		/* Fix up word spacing */
		error = compute_absolute_length_normal(style,
				&ex_size.data.length,
				get_word_spacing, 
				set_word_spacing);
		if (error != CSS_OK)
			return error;
	}

	return CSS_OK;
}
コード例 #20
0
ファイル: text_entry.cpp プロジェクト: jseward/solar
	float text_entry::get_text_width(const std::wstring& text) const {
		return get_font().get_text_width(get_font_size(), text.c_str());
	}
コード例 #21
0
/* parse the properties and return a list of properties. NOTE: 'b' is
   only used for error reporting */
CSSProperty *css_parse_properties(CSSParseState *b, const char *props_str)
{
    const char *p;
    char property[64];
    char buf[1024], buf2[64];
    int property_index, type, val, nb_args, i, unit;
    int property_index1;
    CSSPropertyValue args[MAX_ARGS];
    CSSProperty **last_prop, *first_prop;
    const CSSPropertyDef *def;

    val = 0;
    first_prop = NULL;
    last_prop = &first_prop;
    p = props_str;
    for (;;) {
        get_str(&p, property, sizeof(property), ":");
        if (*p == '\0')
            break;
        if (*p == ':')
            p++;
        skip_spaces(&p);
        /* find the property */
        def = css_properties;
        for (;;) {
            if (def >= css_properties + NB_PROPERTIES) {
                css_error1(b, "unsupported property '%s'", property);
                /* property not found skip it: find next ';' */
                while (*p && *p != ';')
                    p++;
                goto next;
            }
            if (!strcmp(def->name, property))
                break;
            def++;
        }
        property_index = def - css_properties;
        type = def->type;

        nb_args = 0;
        for (;;) {
            /* get argument */
            skip_spaces(&p);
            if (*p == ';' || *p == '\0')
                break;
            /* more than 1 argument only if wanted */
            if (nb_args >= 1 &&
                    !(type & (CSS_TYPE_FOUR|CSS_TYPE_TWO|CSS_TYPE_ARGS)))
                break;
            if (nb_args >= 2 &&
                    !(type & (CSS_TYPE_FOUR|CSS_TYPE_ARGS)))
                break;
            if (nb_args >= 4 &&
                    (!type & CSS_TYPE_ARGS))
                break;
            if (nb_args >= MAX_ARGS)
                break;

            if (*p == '\"' || *p == '\'') {
                /* string parsing */
                /* if no string expected, continue parsing */
                if (!(type & CSS_TYPE_STRING))
                    goto next;
                args[nb_args].u.str = css_parse_string(&p);
                unit = CSS_VALUE_STRING;
                goto got_val;
            }

            if (type & CSS_TYPE_ATTR) {
                /* attr(x) support */
                if (strstart(p, "attr(", &p)) {
                    get_str(&p, buf, sizeof(buf), ");");
                    if (buf[0] != '\0') {
                        if (*p != ')')
                            goto next;
                        p++;
                        if (b->ignore_case)
                            css_strtolower(buf, sizeof(buf));
                        args[nb_args].u.attr_id = css_new_ident(buf);
                        unit = CSS_VALUE_ATTR;
                        goto got_val;
                    }
                }
            }

            if (type & CSS_TYPE_COUNTER) {
                /* counter(x[,type]) support */
                if (strstart(p, "counter(", &p)) {
                    get_str(&p, buf, sizeof(buf), ",);");
                    args[nb_args].u.counter.type = CSS_LIST_STYLE_TYPE_DECIMAL;
                    if (*p == ',') {
                        p++;
                        get_str(&p, buf2, sizeof(buf2), ");");
                        val = css_get_enum(buf2, list_style_enum);
                        if (val >= 0)
                            args[nb_args].u.counter.type = val;
                    }
                    if (*p != ')')
                        goto next;
                    p++;
                    args[nb_args].u.counter.counter_id = css_new_ident(buf);
                    unit = CSS_VALUE_COUNTER;
                    goto got_val;
                }
            }
            get_str(&p, buf, sizeof(buf), ";");

            unit = CSS_UNIT_NONE;
            if (type & CSS_TYPE_AUTO) {
                if (!strcmp(buf, "auto")) {
                    val = CSS_AUTO;
                    goto got_val;
                }
            }
            if (!(type & CSS_TYPE_NOINHERIT)) {
                if (!strcmp(buf, "inherit")) {
                    val = CSS_INHERIT;
                    goto got_val;
                }
            }
            if (type & CSS_TYPE_INTEGER) {
                const char *p1;
                val = strtol(buf, (char **)&p1, 0);
                if (*p1 == '\0') {
                    unit = CSS_VALUE_INTEGER;
                    goto got_val;
                }
            }
            if (type & CSS_TYPE_LENGTH) {
                if (!css_get_length(&val, &unit, buf))
                    goto got_val;
            }
            if (type & CSS_TYPE_BORDER_STYLE) {
                val = css_get_enum(buf, border_style_enum);
                if (val >= 0)
                    goto got_val;
            }
            if (type & CSS_TYPE_LIST_STYLE) {
                val = css_get_enum(buf, list_style_enum);
                if (val >= 0)
                    goto got_val;
            }
            if (type & CSS_TYPE_ENUM) {
                val = css_get_enum(buf, def->name + strlen(def->name) + 1);
                if (val >= 0)
                    goto got_val;
            }
            if (type & CSS_TYPE_IDENT) {
                val = css_new_ident(buf);
                unit = CSS_VALUE_IDENT;
                goto got_val;
            }
            if (type & CSS_TYPE_FONT_FAMILY) {
                val = css_get_font_family(buf);
                if (val == 0)
                    val = CSS_INHERIT;
                goto got_val;
            }
            if (type & CSS_TYPE_COLOR) {
                QEColor color;
                /* XXX: color parsing is not always discriminant */
                if (!css_get_color(&color, buf)) {
                    val = color;
                    unit = CSS_VALUE_COLOR;
                    goto got_val;
                }
            }
            css_error1(b, "unrecognized value '%s' for property '%s'",
                       buf, def->name);
            goto next;
got_val:
            /* specific handling may be necessary. We do them here */
            switch (property_index) {
            case CSS_font_size:
                if (unit == CSS_UNIT_NONE) {
                    if (val == 7) {
                        /* smaller */
                        unit = CSS_UNIT_PERCENT;
                        val = (CSS_LENGTH_FRAC_BASE * 10) / 12;
                    } else if (val == 8) {
                        /* larger */
                        unit = CSS_UNIT_PERCENT;
                        val = (CSS_LENGTH_FRAC_BASE * 12) / 10;
                    } else if (val >= 0) {
                        unit = CSS_UNIT_IN;
                        val = get_font_size(val);
                    } else {
                        goto next;
                    }
                }
                break;
            case CSS_border:
            case CSS_border_left:
            case CSS_border_top:
            case CSS_border_right:
            case CSS_border_bottom:
                if (unit == CSS_VALUE_COLOR) {
                    property_index1 = property_index +
                                      CSS_border_color - CSS_border;
                } else if (unit == CSS_UNIT_NONE) {
                    property_index1 = property_index +
                                      CSS_border_style - CSS_border;
                } else {
                    property_index1 = property_index +
                                      CSS_border_width - CSS_border;
                }
                args[0].type = unit;
                args[0].u.val = val;
                if (property_index == CSS_border) {
                    for (i = 0; i < 4; i++)
                        css_add_prop(&last_prop, property_index1 + 1 + i,
                                     &args[0]);
                } else {
                    css_add_prop(&last_prop, property_index1, &args[0]);
                }
                /* parse next args without storing them */
                continue;
            }

            args[nb_args].type = unit;
            if (unit != CSS_VALUE_STRING &&
                    unit != CSS_VALUE_ATTR &&
                    unit != CSS_VALUE_COUNTER) {
                args[nb_args].u.val = val;
            }
            nb_args++;
        }
        if (type & CSS_TYPE_SPECIAL)
            goto next;

        if (type & CSS_TYPE_FOUR) {
            CSSPropertyValue v1, v2, v3, v4;
            /* handle specifically the four args case */
            v1 = args[0];
            switch (nb_args) {
            case 1:
                args[1] = args[2] = args[3] = v1;
                break;
            case 2:
                v2 = args[1];
                args[1] = args[3] = v1;
                args[0] = args[2] = v2;
                break;
            case 3:
                v2 = args[1];
                v3 = args[2];
                args[1] = v1;
                args[0] = args[2] = v2;
                args[3] = v3;
                break;
            case 4:
            default:
                v2 = args[1];
                v3 = args[2];
                v4 = args[3];

                args[1] = v1;
                args[2] = v2;
                args[3] = v3;
                args[0] = v4;
                break;
            }
            for (i = 0; i < 4; i++)
                css_add_prop(&last_prop, property_index + 1 + i, &args[i]);
        } else if (type & CSS_TYPE_TWO) {
            if (nb_args == 1)
                args[1] = args[0];
            for (i = 0; i < 2; i++)
                css_add_prop(&last_prop, property_index + 1 + i, &args[i]);
        } else if (type & CSS_TYPE_ARGS) {
            /* unbounded number of args */
            css_add_prop_values(&last_prop, property_index, nb_args, args);
        } else {
            css_add_prop(&last_prop, property_index, &args[0]);
        }
next:
        skip_spaces(&p);
        if (*p != ';')
            break;
        p++;
    }
    return first_prop;
}
コード例 #22
0
ファイル: text_entry.cpp プロジェクト: jseward/solar
	float text_entry::get_kerning_pair_offset(wchar_t a, wchar_t b) const {
		return get_font().get_kerning_pair_offset(get_font_size(), a, b);
	}