Exemplo n.º 1
0
void drvJAVA2::show_text(const TextInfo & textinfo)
{
	if (numberOfElements > limitNumberOfElements)
		continue_page();
	unsigned int javaFontNumber = getFontNumber(textinfo.currentFontName.value());
	outf << "    currentPage.add(new PSTextObject(new Color(";
	outf << currentR() << "f, " << currentG() << "f, " << currentB() << "f)," << endl;
	outf << "      \"";
	for (const char *p = textinfo.thetext.value(); (*p) != 0; p++) {
		if ((*p) == '"') {
			outf << '\\' << *p;
		} else if ((*p) == '\\') {
			outf << '\\' << *p;
		} else if ((*p) == (char) 13) {	// ^M
			outf << ' ';
		} else {
			outf << *p;
		}
	}
	outf << "\"," << endl;
	outf << "      " << (textinfo.x +
						 x_offset) << "f, " << (currentDeviceHeight - textinfo.y + y_offset) << "f";
#ifdef PASSFONTNAME
	const char *javaFname = JavaFonts[javaFontNumber].javaname;
	const char *javaFstyle = JavaFonts[javaFontNumber].javastyle;
	outf << ", \"" << javaFname << "\", " << javaFstyle;
#else
	outf << ", " << javaFontNumber;
#endif
	const float *CTM = getCurrentFontMatrix();
	if ((fabs(pythagoras(CTM[0], CTM[1] ) - textinfo.currentFontSize) < 1e-5)
		&& (fabs(pythagoras(CTM[2] ,CTM[3] ) - textinfo.currentFontSize) < 1e-5)
		&& (CTM[0] * CTM[3] - CTM[1] * CTM[2] >= 0)) {
		outf << ", " << textinfo.currentFontSize << "f";
		if (textinfo.currentFontAngle) {
			outf << ", " << textinfo.currentFontAngle << "f";
		}
	} else {
		outf << ", new AffineTransform(" << CTM[0] << "f, " << (-CTM[1]) << "f, ";
		outf << (-CTM[2]) << "f, " << CTM[3] << "f, 0f, 0f)";
	}
	outf << "));" << endl;
	numberOfElements++;
}
Exemplo n.º 2
0
void drvplot::show_text(const TextInfo & textinfo)
{
	if (strlen(textinfo.thetext.value()) > 0) {
		(void)plotter->ffontsize(textinfo.currentFontSize);
		(void)plotter->fontname(textinfo.currentFontName.value());
		(void)plotter->pencolor(plotcolor(textinfo.currentR),
						  plotcolor(textinfo.currentG), plotcolor(textinfo.currentB));
		const float *matrix = getCurrentFontMatrix();
		double sinv;
		if (textinfo.currentFontSize != 0.0)
			sinv = 1.0 / textinfo.currentFontSize;
		else
			sinv = 0.0;
		(void)plotter->savestate();
		(void)plotter->fconcat(sinv * (double) matrix[0],
						 sinv * (double) matrix[1],
						 sinv * (double) matrix[2],
						 sinv * (double) matrix[3], textinfo.x + x_offset, textinfo.y + y_offset);
		(void)plotter->fmove(0.0, 0.0);
		(void)plotter->label(textinfo.thetext.value());
		(void)plotter->restorestate();
	}
}
Exemplo n.º 3
0
void drvCAIRO::show_text(const TextInfo & textinfo)
{
  outf << "  /*" << endl;
  outf << "   * " << "X " << textinfo.x << " Y " << textinfo.y << endl;
  outf << "   * " << "X_END " << textinfo.x_end << " Y_END " << textinfo.y_end << endl;
  outf << "   * " << "currentFontName: " << textinfo.currentFontName.value() << endl;
  outf << "   * " << "is_non_standard_font: " << textinfo.is_non_standard_font << endl;
  outf << "   * " << "currentFontFamilyName: " << textinfo.currentFontFamilyName.value() << endl;
  outf << "   * " << "currentFontFullName: " << textinfo.currentFontFullName.value() << endl;
  outf << "   * " << "currentFontWeight: " << textinfo.currentFontWeight.value() << endl;
  outf << "   * " << "currentFontAngle: " << textinfo.currentFontAngle << endl;

  const float *CTM = getCurrentFontMatrix();
  const char *weight, *slant, *family;

  outf << "   * " << "currentFontMatrix: [";
  for (unsigned int i = 0; i < 6; i++) {
    outf << " " << CTM[i];
  }
  outf << ']' << endl;
  outf << "   */" << endl;

  outf << "  {" << endl;
  outf << "    cairo_matrix_t matrix, save_matrix;" << endl;
  if (options->pango.value) {
    outf << "    PangoFontDescription *desc;" << endl;
    outf << "    PangoLayout *layout;" << endl;
  }
  outf << "    const char *text = \"" << textinfo.thetext.value() << "\";" << endl;
  outf << endl;

  outf << "    cairo_set_source_rgb (cr, " << textinfo.currentR << "," << 
    textinfo.currentG << "," << textinfo.currentB << ");" << endl;

  outf << "    cairo_get_matrix (cr, &save_matrix);" << endl;
  
  // cairo_matrix_init (xx, yx, xy, yy, x0, y0)
  //    x_new = xx * x + xy * y + x0;
  //    y_new = yx * x + yy * y + y0;
  outf << "    cairo_save (cr);" << endl;
  outf << "    cairo_matrix_init (&matrix," 
       << CTM[0]/textinfo.currentFontSize << ", "
       << -1.0*CTM[1]/textinfo.currentFontSize << ", "
       << -1.0*CTM[2]/textinfo.currentFontSize << ", "
       <<  1.0*CTM[3]/textinfo.currentFontSize << ", "
       << CTM[4] + x_offset << ", "
       << -1.0*CTM[5] + y_offset << ");" << endl;

  outf << "    cairo_transform (cr, &matrix);" << endl;
  outf << "    cairo_move_to (cr, 0, 0);" << endl;
  outf << endl;

  family = "monospace";
  if (strstr(textinfo.currentFontName.value(), "Times") ||
      strstr(textinfo.currentFontName.value(), "Roman")) {
    family = "serif";
  } else if (strstr(textinfo.currentFontName.value(), "Helvetica") ||
	     strstr(textinfo.currentFontName.value(), "Sans")) {
    family = "sans-serif";
  } else if (strstr(textinfo.currentFontName.value(), "Courier") ||
	     strstr(textinfo.currentFontName.value(), "Mono")) {
    family = "monospace";
  } else if (strstr(textinfo.currentFontName.value(), "Symbol") ) {
    // In this case, what unfortunately needs to happen is I need to convert the
    // ASCII string to UTF-8 encoded string but with mapping from the 
    family = "symbol";
  } else {
    errf << "currentFontName: " << textinfo.currentFontName.value() << " is not known." << endl;
    errf << "                 Defaulting to " << family << endl;
  }
  
  if (options->pango.value) {
    outf << "    /* Set pango font */" << endl;
    outf << "    layout = pango_cairo_create_layout (cr);" << endl;
    outf << "    desc = pango_font_description_from_string (\"" << 
      family << "\");" << endl;
    
    outf << "    /* A size value of 10 * PANGO_SCALE is a 10 point font. */" << endl;
    outf << "    pango_font_description_set_size (desc,  " << 
      textinfo.currentFontSize << " * PANGO_SCALE);" << endl;
    outf << "    pango_layout_set_font_description (layout, desc);" << endl;
    outf << "    pango_font_description_free (desc);" << endl;
    outf << "    pango_layout_set_text (layout, text, -1);" << endl;
    outf << "    pango_layout_set_alignment(layout, PANGO_ALIGN_LEFT);" << endl;

    outf << "    pango_cairo_show_layout (cr, layout);" << endl;
    outf << "    g_object_unref (layout);" << endl;

  } else {
    // cairo_select_font_face (cairo_t *cr,
    //                         const char *family,
    //                         cairo_font_slant_t slant,
    //                         cairo_font_weight_t weight);
    //
    // family:
    //  standard CSS2 generic family names, ("serif", "sans-serif",
    //  "cursive", "fantasy", "monospace"), are likely to work as expected.
    //
    
    // FIXME -- figure out how to get the family set is a better way
    
    // slant:
    //   CAIRO_FONT_SLANT_NORMAL  - Upright font style
    //   CAIRO_FONT_SLANT_ITALIC  - Italic font style
    //   CAIRO_FONT_SLANT_OBLIQUE - Oblique font style
    //

    // FIXME -- set the slant more robustly
    slant = "CAIRO_FONT_SLANT_NORMAL";
    if (strstr(textinfo.currentFontFullName.value(), "Italic")) {
      slant = "CAIRO_FONT_SLANT_ITALIC";
    } else  if (strstr(textinfo.currentFontFullName.value(), "Oblique")) {
      slant = "CAIRO_FONT_SLANT_OBLIQUE";
    }

    // weight:
    //   CAIRO_FONT_WEIGHT_NORMAL - Normal font weight
    //   CAIRO_FONT_WEIGHT_BOLD   - Bold font weight
    //

    // FIXME -- set the weight more robustly
    weight = "CAIRO_FONT_WEIGHT_NORMAL";
    if (strstr(textinfo.currentFontWeight.value(), "bold") ||
	strstr(textinfo.currentFontWeight.value(), "Bold") ) {
      weight = "CAIRO_FONT_WEIGHT_BOLD";
    }
    
    outf << "    cairo_select_font_face (cr, \"" << family << "\"," << endl;
    outf << "                            " << slant << "," << endl;
    outf << "                            " << weight << ");" << endl;
    
    // outf << "    status = cairo_status (cr);" << endl;
    //outf << "    printf(\"cairo_select_font_face() returned \\\"%s\\\"\\n\", cairo_status_to_string (status));" << endl;
    
    outf << "    cairo_set_font_size (cr, " << textinfo.currentFontSize << ");" << endl;
    outf << "    cairo_show_text (cr, text);" << endl;
  }

  outf << "    cairo_set_matrix (cr, &save_matrix);" << endl;
  outf << "    cairo_restore (cr);" << endl;
  outf << "    cairo_move_to (cr, " << textinfo.x_end + x_offset 
       << ", " << -1*textinfo.y_end + y_offset << ");" << endl;
  outf << "  }" << endl;
  outf << endl;

}