Exemplo n.º 1
0
NEOERR *convert_text_html_alloc_options (const char *src, int slen,
                                         char **out,
                                         HTML_CONVERT_OPTS *opts)
{
  NEOERR *err;
  STRING out_s;
  int formatting = 0;
  HTML_CONVERT_OPTS my_opts;

  string_init(&out_s);

  if (opts == NULL)
  {
    opts = &my_opts;
    opts->bounce_url = NULL;
    opts->url_class = NULL;
    opts->url_target = "_blank";
    opts->mailto_class = NULL;
    opts->long_lines = 0;
    opts->space_convert = 0;
    opts->newlines_convert = 1;
    opts->longline_width = 75; /* This hasn't been used in a while, actually */
    opts->check_ascii_art = 1;
    opts->link_name = NULL;
  }

  do
  {
    if  (opts->check_ascii_art)
    {
	formatting = has_space_formatting (src, slen);
	if (formatting) opts->space_convert = 1;
    }
    if (formatting == 2)
    {
      /* Do <pre> formatting */
      opts->newlines_convert = 1;
      err = string_append (&out_s, "<tt>");
      if (err != STATUS_OK) break;
      err = split_and_convert(src, slen, &out_s, opts);
      if (err != STATUS_OK) break;
      err = string_append (&out_s, "</tt>");
      if (err != STATUS_OK) break;
      /* Strip white space at end of lines */
      strip_white_space_end (&out_s);
    }
    else
    {
      /* int nl = has_long_lines (src, slen); */
      err = split_and_convert(src, slen, &out_s, opts);
    }
  } while (0);
  if (err != STATUS_OK)
  {
    string_clear (&out_s);
    return nerr_pass (err);
  }
  if (out_s.buf == NULL)
  {
    *out = strdup("");
  }
  else
  {
    *out = out_s.buf;
  }
  return STATUS_OK;
}
Exemplo n.º 2
0
// Much like Nehe's glPrint function, but modified to work
// with freetype fonts.
void font_data::print(float x, float y, int align, const char *fmt, ...) {	

	// We want a coordinate system where things coresponding to window pixels.
	pushScreenCoordinateMatrix();	

	//We make the height about 1.5* that of
	float ht= h/.63f;						
	
	char		text[256];								// Holds the string (max of 255 bytes)
	va_list		ap;										// Pointer to list of arguments

	if (fmt == NULL)									// If there's no text
		*text=0;										// do nothing

	else {
		va_start(ap, fmt);								// Parses the string for variables
	    vsprintf(text, fmt, ap);						// and converts symbols to actual numbers
		va_end(ap);										// Results are stored in text
	}

	vector<ucs2string> lines;
	vector<int> widths;

	split_and_convert((uchar*) text, lines, widths);

	glPushAttrib(GL_LIST_BIT | GL_CURRENT_BIT | GL_ENABLE_BIT | GL_TRANSFORM_BIT);	
	glMatrixMode(GL_MODELVIEW);
	glDisable(GL_LIGHTING);
	glEnable(GL_TEXTURE_2D);
	glDisable(GL_DEPTH_TEST);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);	

	glListBase(list_base);

	float modelview_matrix[16];	
	glGetFloatv(GL_MODELVIEW_MATRIX, modelview_matrix);

	//This is where the text display actually happens.
	//For each line of text we reset the modelview matrix
	//so that the line's text will start in the correct position.
	//Notice that we need to reset the matrix, rather than just translating
	//down by h. This is because when each character is
	//draw it modifies the current matrix so that the next character
	//will be drawn immediatly after it.  
	for (unsigned int i = 0; i < lines.size(); ++i) {
		
		float xmod = x;
		float len =	(float) widths[i];		//= text_length(lines[i].c_str());
		if ( align == CENTER ) xmod -= floor(len / 2);
		else if ( align == RIGHT ) xmod -= len;

		glPushMatrix();
		glLoadIdentity();
		glTranslatef(xmod,y-ht*i,0);
		glMultMatrixf(modelview_matrix);

		// Call the display lists using the UCS-2 line.	
		glCallLists((GLsizei)lines[i].length(), GL_UNSIGNED_SHORT, lines[i].c_str());

		glPopMatrix();

	}


	glPopAttrib();		

	pop_projection_matrix();
}