Ejemplo n.º 1
0
bool xls_xml_context::end_element(xmlns_id_t ns, xml_token_t name)
{
    if (ns == NS_xls_xml_ss)
    {
        switch (name)
        {
            case XML_Row:
                ++m_cur_row;
            break;
            case XML_Cell:
                ++m_cur_col;
            break;
            case XML_Data:
                push_cell();
            break;
            default:
                ;
        }
    }
    return pop_stack(ns, name);
}
Ejemplo n.º 2
0
Error RichTextLabel::append_bbcode(const String& p_bbcode) {

	int pos = 0;

	List<String> tag_stack;
	Ref<Font> normal_font=get_font("normal_font");
	Ref<Font> bold_font=get_font("bold_font");
	Ref<Font> italics_font=get_font("italics_font");
	Ref<Font> bold_italics_font=get_font("bold_italics_font");
	Ref<Font> mono_font=get_font("mono_font");

	Color base_color=get_color("default_color");

	int indent_level=0;

	bool in_bold=false;
	bool in_italics=false;

	while(pos < p_bbcode.length()) {


		int brk_pos = p_bbcode.find("[",pos);

		if (brk_pos<0)
			brk_pos=p_bbcode.length();

		if (brk_pos > pos) {
			add_text(p_bbcode.substr(pos,brk_pos-pos));
		}

		if (brk_pos==p_bbcode.length())
			break; //nothing else o add

		int brk_end = p_bbcode.find("]",brk_pos+1);

		if (brk_end==-1) {
			//no close, add the rest
			add_text(p_bbcode.substr(brk_pos,p_bbcode.length()-brk_pos));
			break;
		}


		String tag = p_bbcode.substr(brk_pos+1,brk_end-brk_pos-1);


		if (tag.begins_with("/") && tag_stack.size()) {

			bool tag_ok = tag_stack.size() && tag_stack.front()->get()==tag.substr(1,tag.length());



			if (tag_stack.front()->get()=="b")
				in_bold=false;
			if (tag_stack.front()->get()=="i")
				in_italics=false;
			if (tag_stack.front()->get()=="indent")
				indent_level--;


			if (!tag_ok) {

				add_text("[");
				pos++;
				continue;
			}

			tag_stack.pop_front();
			pos=brk_end+1;
			if (tag!="/img")
				pop();

		} else if (tag=="b") {

			//use bold font
			in_bold=true;
			if (in_italics)
				push_font(bold_italics_font);
			else
				push_font(bold_font);
			pos=brk_end+1;
			tag_stack.push_front(tag);
		} else if (tag=="i") {

			//use italics font
			in_italics=true;
			if (in_bold)
				push_font(bold_italics_font);
			else
				push_font(italics_font);
			pos=brk_end+1;
			tag_stack.push_front(tag);
		} else if (tag=="code") {

			//use monospace font
			push_font(mono_font);
			pos=brk_end+1;
			tag_stack.push_front(tag);
		} else if (tag.begins_with("table=")) {

			int columns = tag.substr(6,tag.length()).to_int();
			if (columns<1)
				columns=1;
			//use monospace font
			push_table(columns);
			pos=brk_end+1;
			tag_stack.push_front("table");
		} else if (tag=="cell") {

			push_cell();
			pos=brk_end+1;
			tag_stack.push_front(tag);
		} else if (tag.begins_with("cell=")) {

			int ratio = tag.substr(6,tag.length()).to_int();
			if (ratio<1)
				ratio=1;
			//use monospace font
			set_table_column_expand(get_current_table_column(),true,ratio);
			push_cell();
			pos=brk_end+1;
			tag_stack.push_front("cell");
		} else if (tag=="u") {

			//use underline
			push_underline();
			pos=brk_end+1;
			tag_stack.push_front(tag);
		} else if (tag=="s") {

			//use strikethrough (not supported underline instead)
			push_underline();
			pos=brk_end+1;
			tag_stack.push_front(tag);
		} else if (tag=="center") {

			//use underline
			push_align(ALIGN_CENTER);
			pos=brk_end+1;
			tag_stack.push_front(tag);
		} else if (tag=="fill") {

			//use underline
			push_align(ALIGN_FILL);
			pos=brk_end+1;
			tag_stack.push_front(tag);
		} else if (tag=="right") {

			//use underline
			push_align(ALIGN_RIGHT);
			pos=brk_end+1;
			tag_stack.push_front(tag);
		} else if (tag=="ul") {

			//use underline
			push_list(LIST_DOTS);
			pos=brk_end+1;
			tag_stack.push_front(tag);
		} else if (tag=="ol") {

			//use underline
			push_list(LIST_NUMBERS);
			pos=brk_end+1;
			tag_stack.push_front(tag);
		} else if (tag=="indent") {

			//use underline
			indent_level++;
			push_indent(indent_level);
			pos=brk_end+1;
			tag_stack.push_front(tag);

		} else if (tag=="url") {

			//use strikethrough (not supported underline instead)
			int end=p_bbcode.find("[",brk_end);
			if (end==-1)
				end=p_bbcode.length();
			String url = p_bbcode.substr(brk_end+1,end-brk_end-1);
			push_meta(url);

			pos=brk_end+1;
			tag_stack.push_front(tag);

		} else if (tag.begins_with("url=")) {

			String url = tag.substr(4,tag.length());
			push_meta(url);
			pos=brk_end+1;
			tag_stack.push_front("url");
		} else if (tag=="img") {

			//use strikethrough (not supported underline instead)
			int end=p_bbcode.find("[",brk_end);
			if (end==-1)
				end=p_bbcode.length();
			String image = p_bbcode.substr(brk_end+1,end-brk_end-1);

			Ref<Texture> texture = ResourceLoader::load(image,"Texture");
			if (texture.is_valid())
				add_image(texture);

			pos=end;
			tag_stack.push_front(tag);
		} else if (tag.begins_with("color=")) {

			String col = tag.substr(6,tag.length());
			Color color;

			if (col.begins_with("#"))
				color=Color::html(col);
			else if (col=="aqua")
				color=Color::html("#00FFFF");
			else if (col=="black")
				color=Color::html("#000000");
			else if (col=="blue")
				color=Color::html("#0000FF");
			else if (col=="fuchsia")
				color=Color::html("#FF00FF");
			else if (col=="gray" || col=="grey")
				color=Color::html("#808080");
			else if (col=="green")
				color=Color::html("#008000");
			else if (col=="lime")
				color=Color::html("#00FF00");
			else if (col=="maroon")
				color=Color::html("#800000");
			else if (col=="navy")
				color=Color::html("#000080");
			else if (col=="olive")
				color=Color::html("#808000");
			else if (col=="purple")
				color=Color::html("#800080");
			else if (col=="red")
				color=Color::html("#FF0000");
			else if (col=="silver")
				color=Color::html("#C0C0C0");
			else if (col=="teal")
				color=Color::html("#008008");
			else if (col=="white")
				color=Color::html("#FFFFFF");
			else if (col=="yellow")
				color=Color::html("#FFFF00");
			else
				color=base_color;



			push_color(color);
			pos=brk_end+1;
			tag_stack.push_front("color");

		} else if (tag.begins_with("font=")) {

			String fnt = tag.substr(5,tag.length());


			Ref<Font> font = ResourceLoader::load(fnt,"Font");
			if (font.is_valid())
				push_font(font);
			else
				push_font(normal_font);

			pos=brk_end+1;
			tag_stack.push_front("font");


		} else {

			add_text("["); //ignore
			pos=brk_pos+1;

		}
	}

	return OK;
}
Ejemplo n.º 3
0
/* This is only complicated because it must deal with overlap, and it wants
   to be smart about copying empty space. . .
 */
void
move_region (struct rng *fm, struct rng *to)
{
  /* Delta {row,col} */
  int dr, dc;
  int nr, nc;
  int ov, dn;
  struct rng del_to_1, del_to_2;
  int do_2, dirs[2];
  int maxr, maxc;
  CELLREF cmax, rmax;
  int cdmax, rdmax;
  int must_repaint = 0;		/* If this move changes cell widths/heights */

  switch (set_to_region (fm, to))
    {
    case 0:
      return;

    case 1:
      io_error_msg ("Can't move source to multiple targets");
      return;

    case 2:
      del_to_1 = *to;

      do_2 = 0;
      dirs[0] = 1;
      dirs[1] = 1;

      /* del_fm_1= *fm; */
      break;

    default:
      /* They overlap.  There are eight ways that
		   they can overlap.  */
      if (to->lc == fm->lc && to->lr < fm->lr)
	{
	  /* State 1:  'from' on bottom */
	  del_to_1.lr = to->lr;
	  del_to_1.lc = to->lc;
	  del_to_1.hr = fm->lr - 1;
	  del_to_1.hc = to->hc;

	  do_2 = 0;
	  dirs[0] = 1;
	  dirs[1] = 1;

	  /* del_fm_1.lr=to->hr+1;	del_fm_1.lc=fm->lc;
			del_fm_1.hr=fm->hr;	del_fm_1.hc=fm->hc; */
	}
      else if (to->lc == fm->lc)
	{
	  /* State 2: 'from' on top */
	  del_to_1.lr = fm->hr + 1;
	  del_to_1.lc = to->lc;
	  del_to_1.hr = to->hr;
	  del_to_1.hc = to->hc;

	  do_2 = 0;
	  dirs[0] = -1;
	  dirs[1] = 1;

	  /* del_fm_1.lr=fm->lr;	del_fm_1.lc=fm->lc;
			del_fm_1.hr=to->lr-1;	del_fm_1.hc=fm->hc; */
	}
      else if (to->lr == fm->lr && to->lc < fm->lc)
	{
	  /* State 3: 'from' on right */
	  del_to_1.lr = to->lr;
	  del_to_1.lc = to->lc;
	  del_to_1.hr = to->hr;
	  del_to_1.hc = fm->lc - 1;

	  do_2 = 0;
	  dirs[0] = 1;
	  dirs[1] = 1;

	  /* del_fm_1.lr=fm->lr;	del_fm_1.lc=to->hc+1;
			del_fm_1.hr=fm->hr;	del_fm_1.hc=fm->hc; */
	}
      else if (to->lr == fm->lr)
	{
	  /* State 4: 'from' on left */
	  del_to_1.lr = to->lr;
	  del_to_1.lc = fm->hc + 1;
	  del_to_1.hr = to->hr;
	  del_to_1.hc = to->hc;

	  do_2 = 0;
	  dirs[0] = 1;
	  dirs[1] = -1;

	  /* del_fm_1.lr=fm->lr;	del_fm_1.lc=fm->lc;
			del_fm_1.hr=fm->hr;	del_fm_1.hc=to->lc-1; */
	}
      else if (fm->lr < to->lr && fm->lc < to->lc)
	{
	  /* State 5: From on topleft */

	  del_to_1.lr = to->lr;
	  del_to_1.lc = fm->hc + 1;
	  del_to_1.hr = fm->hr;
	  del_to_1.hc = to->hc;

	  del_to_2.lr = fm->hr + 1;
	  del_to_2.lc = to->lc;
	  del_to_2.hr = to->hr;
	  del_to_2.hc = to->hc;

	  do_2 = 1;
	  dirs[0] = -1;
	  dirs[1] = -1;

	  /* del_fm_1.lr=fm->lr;	del_fm_1.lc=fm->lc;
			del_fm_1.hr=to->lr-1;	del_fm_1.hc=fm->hc;

			del_fm_2.lr=to->lr;	del_fm_2.lc=fm->lc;
			del_fm_2.hr=fm->hr;	del_fm_2.hc=to->lc-1; */
	}
      else if (fm->lr < to->lr)
	{
	  /* State 6: 'from' on topright */
	  del_to_1.lr = to->lr;
	  del_to_1.lc = to->lc;
	  del_to_1.hr = fm->hr;
	  del_to_1.hc = fm->lc - 1;

	  del_to_2.lr = fm->hr + 1;
	  del_to_2.lc = to->lc;
	  del_to_2.hr = to->hr;
	  del_to_2.hc = to->hc;

	  do_2 = 1;
	  dirs[0] = -1;
	  dirs[1] = 1;

	  /* del_fm_1.lr=fm->lr;	del_fm_1.lc=fm->lc;
			del_fm_1.hr=to->lr-1;	del_fm_1.hc=fm->hc;

			del_fm_2.lr=to->lr;	del_fm_2.lc=to->hc+1;
			del_fm_2.hr=fm->hr;	del_fm_2.hc=fm->hc; */
	}
      else if (fm->lc < to->lc)
	{
	  /* State 7: 'from on bottomleft */
	  del_to_1.lr = to->lr;
	  del_to_1.lc = to->lc;
	  del_to_1.hr = fm->lr - 1;
	  del_to_1.hc = to->hc;

	  del_to_2.lr = fm->lr;
	  del_to_2.lc = fm->hc;
	  del_to_2.hr = to->hr;
	  del_to_2.hc = to->hc;

	  do_2 = 1;
	  dirs[0] = 1;
	  dirs[1] = -1;

	  /* del_fm_1.lr=fm->lr;	del_fm_1.lc=fm->lc;
			del_fm_1.hr=to->hr;	del_fm_1.hc=to->lc-1;

			del_fm_2.lr=to->hr+1;	del_fm_2.lc=fm->lc;
			del_fm_2.hr=to->hr+1;	del_fm_2.hc=to->lc-1; */
	}
      else
	{
	  /* State 8: 'from' on bottomright */
	  del_to_1.lr = to->lr;
	  del_to_1.lc = to->lc;
	  del_to_1.hr = fm->lr - 1;
	  del_to_1.hc = to->hc;

	  del_to_2.lr = fm->lr;
	  del_to_2.lc = to->lc;
	  del_to_2.hr = to->hr;
	  del_to_2.hc = fm->lc - 1;

	  do_2 = 1;
	  dirs[0] = 1;
	  dirs[1] = 1;

	  /* del_fm_1.lr=fm->lr;	del_fm_1.lc=to->hc+1;
			del_fm_1.hr=to->hr;	del_fm_1.hc=fm->hc;

			del_fm_2.lr=to->hr+1;	del_fm_2.lc=fm->lc;
			del_fm_2.hr=fm->hr;	del_fm_2.hc=fm->hc; */
	}
    }
  dn = to->hr - fm->hr;
  ov = to->hc - fm->hc;

  dr = fm->hr - fm->lr;
  dc = fm->hc - fm->lc;

  delete_region (&del_to_1);
  if (do_2)
    delete_region (&del_to_2);

  if (to->lr == MIN_ROW && to->hr == MAX_ROW)
    {
      shift_widths (ov, fm->lc, fm->hc);
      must_repaint = 1;
    }

  if (to->lc == MIN_COL && to->hc == MAX_COL)
    {
      shift_heights (dn, fm->lr, fm->hr);
      must_repaint = 1;
    }

  shift_outside (fm, dn, ov);

  rmax = highest_row ();
  if (rmax < fm->lr)
    rdmax = -1;
  else if (rmax > fm->hr)
    rdmax = dr;
  else
    rdmax = rmax - fm->lr;
  nr = (dirs[0] > 0) ? 0 : rdmax;
  maxr = (dirs[0] > 0) ? rdmax + 1 : -1;
  for (; nr != maxr; nr += dirs[0])
    {
      cmax = max_col (fm->lr + nr);
      if (cmax < fm->lc)
	cdmax = -1;
      else if (cmax > fm->hc)
	cdmax = dc;
      else
	{
	  cdmax = cmax - fm->lc;
	}
      nc = (dirs[1] > 0) ? 0 : cdmax;
      maxc = (dirs[1] > 0) ? cdmax + 1 : -1;
      for (; nc != maxc; nc += dirs[1])
	{
	  CELLREF rf, cf, rt, ct;
	  CELL *cpf;

	  rf = fm->lr + nr;
	  cf = fm->lc + nc;
	  rt = to->lr + nr;
	  ct = to->lc + nc;

	  cpf = find_cell (rf, cf);
	  cur_row = rt;
	  cur_col = ct;
	  my_cell = find_cell (cur_row, cur_col);
	  if ((!cpf || (!cpf->cell_font &&
		((cpf->cell_flags.cell_format == 0)
		&& (cpf->cell_flags.cell_precision == 0)
		&& (cpf->cell_flags.cell_justify == 0)
		&& (cpf->cell_flags.cell_type == 0))
		&& (cpf->cell_flags.cell_lock == 0)
		&& !cpf->cell_formula))
	      && !my_cell)
	    continue;

	  if (!cpf)
	    {
	      bzero(&(my_cell->cell_flags), sizeof(my_cell->cell_flags));
	      my_cell->cell_font = 0;
	      my_cell->cell_refs_to = 0;
	      my_cell->cell_formula = 0;
	      my_cell->cell_cycle = 0;
	      my_cell = 0;
	      continue;
	    }
	  if (!my_cell)
	    {
	      my_cell = find_or_make_cell (cur_row, cur_col);
	      cpf = find_cell (rf, cf);
	    }
	  else
	    flush_old_value ();

	  my_cell->cell_flags = cpf->cell_flags;
	  my_cell->cell_font = cpf->cell_font;
	  my_cell->cell_refs_to = cpf->cell_refs_to;
	  my_cell->cell_formula = cpf->cell_formula;
	  my_cell->cell_cycle = cpf->cell_cycle;
	  my_cell->c_z = cpf->c_z;

	  bzero(&(cpf->cell_flags), sizeof(cpf->cell_flags));
	  cpf->cell_font = 0;
	  cpf->cell_refs_to = 0;
	  cpf->cell_formula = 0;
	  cpf->cell_cycle = 0;

	  push_cell (cur_row, cur_col);

 	  if (!must_repaint)
	    {
	      if (cpf)
		io_pr_cell (rf, cf, cpf);
	      if (my_cell)
		io_pr_cell (rt, ct, my_cell);
	    }
	  my_cell = 0;
	}
    }
  if (must_repaint)
    io_repaint ();
/* Perpetration of an interface change here.  If we really
 * need to get back to the old region, we can do it by
 * wrapping the move-region command in macros that set
 * and return to a hardy mark.  We might, however, want
 * to jump the moved text again, or reformat it in some
 * way, so the mark should travel with us.
 * 
 * to->lr and to->lc give the lowest column and row (northwest
 * corner) in the destination region, to->hr and to->hc five the
 * highest, or southeast corner.  The absolute value if their
 * difference tells us how far to move over and down from
 * northwest to mark the region just moved.  This way the new
 * region can be operated on as a chunk immediately
 *
 * --FB 1997.12.17
 */
  if (mkrow != NON_ROW) {
      mkrow = to->lr + abs(to->lr - to->hr);
      mkcol = to->lc + abs(to->lc - to->hc);
  }
  goto_region (to);
  return;
}