CUPS 1.4.3 && printing UTF-8 text

Matthias Apitz guru at unixarea.de
Wed Sep 21 11:24:37 PDT 2011


>
> >
> > On Mon, 2010-07-19 at 08:14 -0700, Helge Blischke wrote:
> > > You will need to get (buy?) a full featured monospaced font and probably=20
> > > modify the texttops filter to handle that fon(s) if it is not a plain typ=
> > e1=20
> > > font.
> >
> > ....or use the paps-based 'texttopaps' filter, which uses pango to get
> > glyph coverage from other fonts when necessary.
> >
> > Tim.

Hello,

I want to summarize the results of my two weeks investigation of this
issue, just for the records and Don Google, in case someone else comes
to the same needs.

1)
I could not find any sources for a 'texttopaps' filter. It seems that
this only exists in form of a patch in RedHat environment and based on
the paps-0.6.8 sources itself; 'paps' has no further development
since 2006.

2)
Based on the hints and with the help of the author of 'paps', I learned
how to render UTF-8 text (including CJK) to PostScript using Pango and
Cairo API directly, which seems after all very powerfull; it is even
simple to get glyph coverage from any other font, placed in the correct
locations, in my case for example for OCR-B font; I'm attaching at the end
a small C source as a starting point which shows how this could be done
outside the CUPS world;

HIH

	matthias

#include <stdio.h>
#include <math.h>
#include <pango/pangocairo.h>
#include <cairo/cairo-ps.h>

// dimensions of the A4 page
//
#define PAGE_WIDTH  595
#define PAGE_HEIGHT 842

void rendertext(cairo_t *cr, char *text, float line);

int main(int argc, char* argv[]) {
	cairo_t *cr;
	cairo_status_t status;
	cairo_surface_t *surface;

	surface = cairo_ps_surface_create("my1st.ps", PAGE_WIDTH, PAGE_HEIGHT);
	status = cairo_surface_status (surface);
	if (status != CAIRO_STATUS_SUCCESS) {
		// if 'status' was not set to indicate a successful operation, error
		printf("cairo_ps_surface_create() does not give CAIRO_STATUS_SUCCESS\n");
		return 1;
	}
	cr = cairo_create(surface);
	cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
	cairo_paint(cr);

	cairo_ps_surface_dsc_begin_page_setup (surface);
	cairo_ps_surface_dsc_comment (surface, "%%PageOrientation: Portrait");

	cairo_ps_surface_dsc_comment (surface, "%%Title: My 1st Cairo-PS document");
	cairo_ps_surface_dsc_comment (surface, "%%Copyright: Copyright (C) 2011 guru at unixarea.de");

	cairo_ps_surface_dsc_begin_setup (surface);
	cairo_ps_surface_dsc_comment (surface, "%%IncludeFeature: *MediaColor White");

	cairo_ps_surface_dsc_begin_page_setup (surface);
	cairo_ps_surface_dsc_comment (surface, "%%IncludeFeature: *PageSize A4");
	cairo_ps_surface_dsc_comment (surface, "%%IncludeFeature: *InputSlot LargeCapacity");
	cairo_ps_surface_dsc_comment (surface, "%%IncludeFeature: *MediaType Glossy");
	cairo_ps_surface_dsc_comment (surface, "%%IncludeFeature: *MediaColor Blue");

	rendertext(cr, "<i>Arabic</i> السلام عليكم ", 20.0);
	rendertext(cr, "<b>Bengali</b> (বাঙ্লা)	ষাগতোম", 60.0);
	rendertext(cr, "<i><b>Greek</b></i> (Ελληνικά)  Γειά σας", 100.0);
	rendertext(cr, "<u>Hebrew</u> שָׁלוֹם", 140.0);
	rendertext(cr, "<b>Japanese  (日本語) こんにちは, コンニチハ </b>", 180.0);
	rendertext(cr, "Chinese  (中文,普通话,汉语) 你好", 220.0);
	rendertext(cr, "Vietnamese	(Tiếng Việt)	Xin Chào", 260.0);

	rendertext(cr, "<span font=\"OCRB 12\">ABC 0123456789</span>", 300.0);

	rendertext(cr, "Español ¡Que vivan los sueños!", 340.0);
	rendertext(cr, "normal and OCR on same line: <span font=\"OCRB 12\">ABC 0123456789</span>", 380.0);

	cairo_show_page(cr);

	cairo_ps_surface_dsc_comment (surface, "%%IncludeFeature: *PageSize A4");

	cairo_destroy(cr);
	cairo_surface_destroy(surface);

	return 0;
}

void rendertext(cairo_t *cr, char *text, float line) {
	PangoLayout *layout;
	PangoFontDescription *desc;

	layout = pango_cairo_create_layout(cr);

	pango_layout_set_markup(layout, text, -1);

	desc = pango_font_description_from_string("Monospace 16");
	pango_layout_set_font_description(layout, desc);
	pango_font_description_free(desc);

	cairo_set_source_rgb(cr, 0.0, 0.0, 1.0);
	pango_cairo_update_layout(cr, layout);

	cairo_move_to(cr, 20, line);

	pango_cairo_show_layout(cr, layout);

	g_object_unref(layout);
}





More information about the cups mailing list