示例#1
0
文件: basic.c 项目: ricksladkey/vile
/*
 * Implements the vi "^F" command.
 *
 * Scroll forward by a specified number of lines, or by a full page if no
 * argument.
 */
int
forwpage(int f, int n)
{
    LINE *lp;
    int status;

    if ((n = full_pages(f, n)) < 0)
	return backpage(f, -n);

    if ((status = (lforw(DOT.l) != buf_head(curbp))) == TRUE) {
	lp = curwp->w_line.l;
	n -= line_height(curwp, lp);
	while (lp != buf_head(curbp)) {
	    lp = lforw(lp);
	    if ((n -= line_height(curwp, lp)) < 0)
		break;
	}
	if (n < 0)
	    curwp->w_line.l = lp;
	DOT.l = lp;
	(void) firstnonwhite(FALSE, 1);
	curwp->w_flag |= WFHARD | WFMODE;
    }
    return status;
}
示例#2
0
文件: basic.c 项目: ricksladkey/vile
/* ARGSUSED */
int
gotomos(int f GCC_UNUSED, int n)
{
    LINE *last = DOT.l;
    LINE *lp, *head;
    int half = (curwp->w_ntrows + 1) / 2;

    head = buf_head(curbp);
    for (n = 0, lp = curwp->w_line.l; lp != head; lp = lforw(lp)) {
	if (n < half)
	    DOT.l = lp;
	if ((n += line_height(curwp, lp)) >= curwp->w_ntrows)
	    break;
    }
    if (n < curwp->w_ntrows) {	/* then we hit eof before eos */
	half = (n + 1) / 2;	/* go back up */
	for (n = 0, lp = curwp->w_line.l; lp != head; lp = lforw(lp)) {
	    DOT.l = lp;
	    if ((n += line_height(curwp, lp)) >= half)
		break;
	}
    }

    if (DOT.l != last)
	curwp->w_flag |= WFMOVE;
    return firstnonwhite(FALSE, 1);
}
示例#3
0
文件: basic.c 项目: ricksladkey/vile
/*
 * Implements the vi "^U" command.
 *
 * This command is like "forwpage", but it goes backwards.  It returns false
 * only if the cursor is on the first line of the buffer.
 *
 * Unlike vi, the OPT_CVMVAS option causes the repeat-count to be interpreted as
 * half-pages, rather than lines.
 */
int
backhpage(int f, int n)
{
    LINE *llp, *dlp;
    int status;

    if ((n = half_pages(f, n)) < 0)
	return forwhpage(f, -n);

    llp = curwp->w_line.l;
    dlp = DOT.l;
    if ((status = (lback(dlp) != buf_head(curbp))) == TRUE) {
	n -= line_height(curwp, dlp);
	while (lback(dlp) != buf_head(curbp)) {
	    llp = lback(llp);
	    dlp = lback(dlp);
	    if ((n -= line_height(curwp, dlp)) < 0)
		break;
	}
	curwp->w_line.l = llp;
	DOT.l = dlp;
	curwp->w_flag |= WFHARD | WFINS;
    }
    (void) firstnonwhite(FALSE, 1);
    return status;
}
示例#4
0
文件: basic.c 项目: ricksladkey/vile
/*
 * Implements the vi "L" command.
 *
 * Move to the last (or nth last) line in window
 */
int
gotoeos(int f, int n)
{
    LINE *last = DOT.l;
    int nn;

    n = need_at_least(f, n, 1);

    /* first get to the end */
    DOT.l = curwp->w_line.l;
    nn = curwp->w_ntrows;
    while ((nn -= line_height(curwp, DOT.l)) > 0) {
	if (is_last_line(DOT, curbp))
	    break;
	DOT.l = lforw(DOT.l);
    }
#ifdef WMDLINEWRAP
    /* adjust if we pointed to a line-fragment */
    if (w_val(curwp, WMDLINEWRAP)
	&& nn < 0
	&& DOT.l != curwp->w_line.l)
	DOT.l = lback(DOT.l);
#endif
    /* and then go back up */
    /* (we're either at eos or eof) */
    while (--n != 0) {
	if (sameline(DOT, curwp->w_line))
	    break;
	DOT.l = lback(DOT.l);
    }
    if (DOT.l != last)
	curwp->w_flag |= WFMOVE;
    return firstnonwhite(FALSE, 1);
}
示例#5
0
文件: basic.c 项目: ricksladkey/vile
/*
 * Implements the vi "^B" command.
 *
 * This command is like "forwpage", but it goes backwards.
 */
int
backpage(int f, int n)
{
    LINE *lp;
    int status;

    if ((n = full_pages(f, n)) < 0)
	return forwpage(f, -n);

    lp = curwp->w_line.l;
    if (lback(lp) != buf_head(curbp)) {
	while ((n -= line_height(curwp, lp)) >= 0
	       && lback(lp) != buf_head(curbp))
	    lp = lback(lp);
	curwp->w_line.l = lp;
	(void) gotoeos(FALSE, 1);
	curwp->w_flag |= WFHARD | WFMODE;
	status = TRUE;
    } else if (DOT.l != lp) {
	DOT.l = lp;
	curwp->w_flag |= WFHARD | WFMODE;
	status = TRUE;
    } else {
	status = FALSE;
    }
    return status;
}
示例#6
0
	void BuiltIn::paint(const std::string& utf8, int x, int y, uint32_t color, Canvas* canvas) const
	{
		uint32_t palette[256];
		color &= 0x00FFFFFF;
		for (uint32_t alpha = 0; alpha < 0x100; ++alpha)
			palette[alpha] = color | (alpha << 24);

		auto cr = x;

		auto text = utf8::to32(utf8);
		for (auto&& c : text)
		{
			if (c == ' ')
			{
				x += glyph_width;
				continue;
			}
			if (c == '\n')
			{
				y += line_height();
				x = cr;
				continue;
			}
			auto glyph = glyph_id(c);
			if (glyph < 0) continue;
			font::paint(glyph, x, y, palette, canvas);
			x += glyph_width;
		}
	}
示例#7
0
文件: edit.c 项目: jff/mathspad
static void edit_layout_change(void *data)
{
    EDITINFO *einf = (EDITINFO *) data;

    if (!data) return;
    if (!einf->iconized)
	XClearArea(display, einf->drawwin_id, 0, 0, 0, 0, MP_True);
    scrollbar_linesize(einf->scrollver, line_height());
}
void CSSParserLineHeight::parse(const std::string &name, const std::vector<CSSToken> &tokens, std::vector<std::unique_ptr<CSSPropertyValue> > &inout_values)
{
    std::unique_ptr<CSSValueLineHeight> line_height(new CSSValueLineHeight());

    size_t pos = 0;
    CSSToken token = next_token(pos, tokens);
    if (token.type == CSSToken::type_ident && pos == tokens.size())
    {
        if (equals(token.value, "normal"))
            line_height->type = CSSValueLineHeight::type_normal;
        else if (equals(token.value, "inherit"))
            line_height->type = CSSValueLineHeight::type_inherit;
        else
            return;
    }
    else if (token.type == CSSToken::type_number && pos == tokens.size())
    {
        line_height->type = CSSValueLineHeight::type_number;
        line_height->number = StringHelp::text_to_float(token.value);
    }
    else if (is_length(token) && pos == tokens.size())
    {
        CSSLength length;
        if (parse_length(token, length))
        {
            line_height->type = CSSValueLineHeight::type_length;
            line_height->length = length;
        }
        else
        {
            return;
        }
    }
    else if (token.type == CSSToken::type_percentage && pos == tokens.size())
    {
        line_height->type = CSSValueLineHeight::type_percentage;
        line_height->percentage = StringHelp::text_to_float(token.value);
    }
    else
    {
        return;
    }

    inout_values.push_back(std::move(line_height));
}
示例#9
0
文件: basic.c 项目: ricksladkey/vile
/*
 * Implements the vi "H" command.
 *
 * Move to first (or nth) line in window
 */
int
gotobos(int f, int n)
{
    LINE *last = DOT.l;
    int nn = curwp->w_ntrows;

    n = need_at_least(f, n, 1);

    DOT.l = curwp->w_line.l;
    while (--n != 0) {
	if (is_last_line(DOT, curbp))
	    break;
	nn -= line_height(curwp, DOT.l);
	DOT.l = lforw(DOT.l);
    }

    if (DOT.l != last)
	curwp->w_flag |= WFMOVE;
    return firstnonwhite(FALSE, 1);
}
示例#10
0
		unsigned textbox::line_pixels() const
		{
			internal_scope_guard lock;
			auto editor = get_drawer_trigger().editor();
			return (editor ? editor->line_height() : 0);
		}
示例#11
0
文件: edit.c 项目: jff/mathspad
void edit_open(void)
{
    int x = INTERSPACE;
    int y = INTERSPACE;
    unsigned int w=4,h=4;
    int i;
    XSizeHints size_hints;
    EDITINFO *einf;

    state_window = NULL;
    if ( (einf = (EDITINFO *) malloc( sizeof(EDITINFO) )) == NULL)
	message(MP_ERROR, translate("Out of memory in edit."));
    else {
	if (!state_open)
	    if (!last_xpos && !last_ypos) {
		last_xpos = (display_width - last_width)/2;
		last_ypos = (display_height - last_height)/2;
	    }
	einf->xpos = last_xpos;
	einf->ypos = last_ypos;
	einf->width = last_width;
	einf->height = last_height;
	einf->saved = MP_True;
	einf->auto_saved = MP_True;
	einf->view_mode = MP_False;
	einf->empty = MP_True;
	einf->iconized  = MP_True;
	einf->shell = MP_False;
	einf->fini = MP_False;
	einf->strt = MP_False;
	einf->buflen=0;
	einf->pid=0;
	einf->prcsbuf=NULL;
	einf->win_id = XCreateWindow(display, root_window, einf->xpos,
				     einf->ypos, einf->width, einf->height,
				     BORDERWIDTH, CopyFromParent, InputOutput,
				     visual,
				     edit_mask, &edit_attr);
	if (state_open)
	    size_hints.flags = USPosition | USSize | PMinSize;
	else
	    size_hints.flags = PPosition | PSize | PMinSize;
	wm_hints.initial_state =
	    ((iconic || as_icon) ? IconicState : NormalState);
	size_hints.min_width =
	    size_hints.min_height = pos_y_with + SCROLLBARSIZE*3;
	XSetWMProperties(display, einf->win_id, NULL, NULL,
			 NULL, 0, &size_hints, &wm_hints, &class_hints);
	wm_hints.initial_state = NormalState;
	set_protocols(einf->win_id);

	i=0;
	einf->headername = NULL;
	einf->filename = NULL;
	einf->pathname = NULL;
	einf->outputname = NULL;
	if (set_name(einf, NULL) &&
	    add_window(einf->win_id, MAINEDITWINDOW,
		       root_window, (void *) einf, translate(helpname[EDITHELP]))) {
	    while (i<NR_BUTTON &&
		   button_make(i, einf->win_id, translate(editbutton[perm[i]]), &x, y, 1,
			       (void*) einf, helpname[edithelp[i]],
			       NULL, NULL, edit_handle_button,
			       edit_handle_button, edit_handle_button, NULL))
		i++,x+=BINTERSPACE;
	    w = sub_width(last_width);
	    h = sub_height(last_height);
	    if (i==NR_BUTTON) {
		einf->drawwin_id =
		    XCreateWindow(display, einf->win_id,
				  pos_x_with, pos_y_with, w-2, h-2, 1,
				  CopyFromParent, InputOutput,
				  visual,
				  edit_mask, &edit_attr);
		if (add_window(einf->drawwin_id, EDITWINDOW,
			       einf->win_id, NULL, translate(helpname[EDITSUBHELP])))
		    i++;
	    }
	    if (i==NR_BUTTON +1 &&
		(einf->scrollhor =
		 scrollbar_make(HORIZONTAL, einf->win_id, pos_x_with,
				pos_y_without, w, font_width(),
				edit_scrollto, (void*) einf)))
		i++;
	    if (i==NR_BUTTON+2 &&
		(einf->scrollver =
		 scrollbar_make(VERTICAL, einf->win_id, pos_x_without,
				pos_y_with, h, line_height(),
				edit_scrollto, (void*) einf)))
		i++;
	    
	}
	if (i<NR_BUTTON+3) {
	    free(einf->headername);
	    free(einf->pathname);
	    free(einf->filename);
	    XDestroyWindow(display, einf->win_id);
	    destroy_window(einf->win_id);
	} else {
	    is_opened = MP_True;
	    scrollbar_set(einf->scrollver, 0, 1);
	    scrollbar_set(einf->scrollhor, 0, 80);
	    move_selection = !as_icon;
	    einf->info = open_editwindow(&einf->drawwin_id, w-2, h-2);
	    move_selection = MP_False;
	    (void) window_changed(einf->info);
	    number_icon++;
	    number_open++;
	    edit_is_open = MP_True;
	    edit_iconized = (number_icon==number_open);
	    state_window = einf;
	    XMapSubwindows(display, einf->win_id);
	    XMapWindow(display, einf->win_id);
	}
    }
}
示例#12
0
void CSSParserFont::parse(const std::string &propname, const std::vector<CSSToken> &tokens, std::vector<std::unique_ptr<CSSPropertyValue> > &inout_values)
{
	std::unique_ptr<CSSValueFontStyle> style(new CSSValueFontStyle());
	std::unique_ptr<CSSValueFontVariant> variant(new CSSValueFontVariant());
	std::unique_ptr<CSSValueFontWeight> weight(new CSSValueFontWeight());
	std::unique_ptr<CSSValueFontSize> size(new CSSValueFontSize());
	std::unique_ptr<CSSValueLineHeight> line_height(new CSSValueLineHeight());
	std::unique_ptr<CSSValueFontFamily> family(new CSSValueFontFamily());
	style->type = CSSValueFontStyle::type_normal;
	variant->type = CSSValueFontVariant::type_normal;
	weight->type = CSSValueFontWeight::type_normal;
	size->type = CSSValueFontSize::type_medium;
	line_height->type = CSSValueLineHeight::type_normal;
	family->type = CSSValueFontFamily::type_names;
	family->names.push_back(CSSValueFontFamilyName());

	bool font_style_set = false;
	bool font_variant_set = false;
	bool font_weight_set = false;
	int normal_count = 0;
	size_t pos = 0;
	CSSToken token;
	while (pos < tokens.size())
	{
		token = next_token(pos, tokens);
		if (token.type == CSSToken::type_ident)
		{
			if (tokens.size() == 1 &&
				(equals(token.value, "caption") ||
				equals(token.value, "icon") ||
				equals(token.value, "menu") ||
				equals(token.value, "message-box") ||
				equals(token.value, "small-caption") ||
				equals(token.value, "status-bar")))
			{
				inout_values.push_back(std::move(style));
				inout_values.push_back(std::move(variant));
				inout_values.push_back(std::move(weight));
				inout_values.push_back(std::move(size));
				inout_values.push_back(std::move(line_height));
				inout_values.push_back(std::move(family));
				return;
			}
			else if (equals(token.value, "inherit") && tokens.size() == 1)
			{
				style->type = CSSValueFontStyle::type_inherit;
				variant->type = CSSValueFontVariant::type_inherit;
				weight->type = CSSValueFontWeight::type_inherit;
				size->type = CSSValueFontSize::type_inherit;
				line_height->type = CSSValueLineHeight::type_inherit;
				family->type = CSSValueFontFamily::type_inherit;
				
				inout_values.push_back(std::move(style));
				inout_values.push_back(std::move(variant));
				inout_values.push_back(std::move(weight));
				inout_values.push_back(std::move(size));
				inout_values.push_back(std::move(line_height));
				inout_values.push_back(std::move(family));
				return;
			}
			else if (equals(token.value, "normal")) // font-style or font-weight or font-variant
			{
				int allowed = 3;
				if (font_style_set)
					allowed--;
				if (font_weight_set)
					allowed--;
				if (font_variant_set)
					allowed--;
				if (normal_count < allowed)
					normal_count++;
			}
			else if (equals(token.value, "italic") && !font_style_set) // font-style
			{
				font_style_set = true;
				style->type = CSSValueFontStyle::type_italic;
			}
			else if (equals(token.value, "oblique") && !font_style_set) // font-style
			{
				font_style_set = true;
				style->type = CSSValueFontStyle::type_oblique;
			}
			else if (equals(token.value, "small-caps") && !font_variant_set) // font-variant
			{
				font_style_set = true;
				variant->type = CSSValueFontVariant::type_small_caps;
			}
			else if (equals(token.value, "bold") && !font_weight_set) // font-weight
			{
				font_weight_set = true;
				weight->type = CSSValueFontWeight::type_bold;
			}
			else if (equals(token.value, "bolder") && !font_weight_set) // font-weight
			{
				font_weight_set = true;
				weight->type = CSSValueFontWeight::type_bolder;
			}
			else if (equals(token.value, "lighter") && !font_weight_set) // font-weight
			{
				font_weight_set = true;
				weight->type = CSSValueFontWeight::type_lighter;
			}
			else if (token.value == "100" && !font_weight_set) // font-weight
			{
				font_weight_set = true;
				weight->type = CSSValueFontWeight::type_100;
			}
			else if (token.value == "200" && !font_weight_set) // font-weight
			{
				font_weight_set = true;
				weight->type = CSSValueFontWeight::type_200;
			}
			else if (token.value == "300" && !font_weight_set) // font-weight
			{
				font_weight_set = true;
				weight->type = CSSValueFontWeight::type_300;
			}
			else if (token.value == "400" && !font_weight_set) // font-weight
			{
				font_weight_set = true;
				weight->type = CSSValueFontWeight::type_400;
			}
			else if (token.value == "500" && !font_weight_set) // font-weight
			{
				font_weight_set = true;
				weight->type = CSSValueFontWeight::type_500;
			}
			else if (token.value == "600" && !font_weight_set) // font-weight
			{
				font_weight_set = true;
				weight->type = CSSValueFontWeight::type_600;
			}
			else if (token.value == "700" && !font_weight_set) // font-weight
			{
				font_weight_set = true;
				weight->type = CSSValueFontWeight::type_700;
			}
			else if (token.value == "800" && !font_weight_set) // font-weight
			{
				font_weight_set = true;
				weight->type = CSSValueFontWeight::type_800;
			}
			else if (token.value == "900" && !font_weight_set) // font-weight
			{
				font_weight_set = true;
				weight->type = CSSValueFontWeight::type_900;
			}
			else
			{
				break;
			}
		}
		else
		{
			break;
		}
	}

	if (pos == tokens.size())
	{
		debug_parse_error(propname, tokens);
		return;
	}

	if (token.type == CSSToken::type_ident)
	{
		if (equals(token.value, "xx-small"))
			size->type = CSSValueFontSize::type_xx_small;
		else if (equals(token.value, "x-small"))
			size->type = CSSValueFontSize::type_x_small;
		else if (equals(token.value, "small"))
			size->type = CSSValueFontSize::type_small;
		else if (equals(token.value, "medium"))
			size->type = CSSValueFontSize::type_medium;
		else if (equals(token.value, "large"))
			size->type = CSSValueFontSize::type_large;
		else if (equals(token.value, "x-large"))
			size->type = CSSValueFontSize::type_x_large;
		else if (equals(token.value, "xx-large"))
			size->type = CSSValueFontSize::type_xx_large;
		else if (equals(token.value, "smaller"))
			size->type = CSSValueFontSize::type_smaller;
		else if (equals(token.value, "larger"))
			size->type = CSSValueFontSize::type_larger;
		else if (equals(token.value, "inherit"))
			size->type = CSSValueFontSize::type_inherit;
		else
		{
			debug_parse_error(propname, tokens);
			return;
		}
	}
	else if (is_length(token))
	{
		CSSLength length;
		if (parse_length(token, length))
		{
			size->type = CSSValueFontSize::type_length;
			size->length = length;
		}
		else
		{
			debug_parse_error(propname, tokens);
			return;
		}
	}
	else if (token.type == CSSToken::type_percentage)
	{
		size->type = CSSValueFontSize::type_percentage;
		size->percentage = StringHelp::text_to_float(token.value);
	}
	else
	{
		debug_parse_error(propname, tokens);
		return;
	}

	token = next_token(pos, tokens);
	if (token.type == CSSToken::type_delim && token.value == "/")
	{
		token = next_token(pos, tokens);

		if (token.type == CSSToken::type_ident)
		{
			if (equals(token.value, "normal"))
				line_height->type = CSSValueLineHeight::type_normal;
			else if (equals(token.value, "inherit"))
				line_height->type = CSSValueLineHeight::type_inherit;
			else
			{
				debug_parse_error(propname, tokens);
				return;
			}
		}
		else if (token.type == CSSToken::type_number)
		{
			line_height->type = CSSValueLineHeight::type_number;
			line_height->number = StringHelp::text_to_float(token.value);
		}
		else if (is_length(token))
		{
			CSSLength length;
			if (parse_length(token, length))
			{
				line_height->type = CSSValueLineHeight::type_length;
				line_height->length = length;
			}
			else
			{
				debug_parse_error(propname, tokens);
				return;
			}
		}
		else if (token.type == CSSToken::type_percentage)
		{
			line_height->type = CSSValueLineHeight::type_percentage;
			line_height->percentage = StringHelp::text_to_float(token.value);
		}
		else
		{
			debug_parse_error(propname, tokens);
			return;
		}

		token = next_token(pos, tokens);
	}

	family->names.clear();
	while (true)
	{
		if (token.type == CSSToken::type_ident)
		{
			CSSValueFontFamilyName name;
			if (equals(token.value, "serif"))
			{
				name.type = CSSValueFontFamilyName::type_serif;
			}
			else if (equals(token.value, "sans-serif"))
			{
				name.type = CSSValueFontFamilyName::type_sans_serif;
			}
			else if (equals(token.value, "cursive"))
			{
				name.type = CSSValueFontFamilyName::type_cursive;
			}
			else if (equals(token.value, "fantasy"))
			{
				name.type = CSSValueFontFamilyName::type_fantasy;
			}
			else if (equals(token.value, "monospace"))
			{
				name.type = CSSValueFontFamilyName::type_monospace;
			}
			else if (equals(token.value, "default"))
			{
				// reserved for future use
				return;
			}
			else if (equals(token.value, "initial"))
			{
				// reserved for future use
				return;
			}
			else
			{
				name.type = CSSValueFontFamilyName::type_family_name;
			}

			if (name.type == CSSValueFontFamilyName::type_family_name)
			{
				name.name = token.value;
				while (pos != tokens.size())
				{
					token = tokens[pos++];
					if (token.type == CSSToken::type_whitespace)
					{
						name.name += " ";
					}
					else if (token.type == CSSToken::type_ident)
					{
						name.name += token.value;
					}
					else if (token.type == CSSToken::type_delim && token.value == ",")
					{
						break;
					}
				}
				family->names.push_back(name);
				if (pos == tokens.size())
					break;
				token = next_token(pos, tokens);
			}
			else
			{
				family->names.push_back(name);

				if (pos == tokens.size())
					break;
				token = next_token(pos, tokens);
				if (token.type != CSSToken::type_delim || token.value != ",")
				{
					debug_parse_error(propname, tokens);
					return;
				}
				token = next_token(pos, tokens);
			}
		}
		else if (token.type == CSSToken::type_string)
		{
			CSSValueFontFamilyName name;
			name.type = CSSValueFontFamilyName::type_family_name;
			name.name = token.value;
			family->names.push_back(name);

			if (pos == tokens.size())
				break;
			token = next_token(pos, tokens);
			if (token.type != CSSToken::type_delim || token.value != ",")
			{
				debug_parse_error(propname, tokens);
				return;
			}
			token = next_token(pos, tokens);
		}
		else
		{
			debug_parse_error(propname, tokens);
			return;
		}
	}

	inout_values.push_back(std::move(style));
	inout_values.push_back(std::move(variant));
	inout_values.push_back(std::move(weight));
	inout_values.push_back(std::move(size));
	inout_values.push_back(std::move(line_height));
	inout_values.push_back(std::move(family));
}