rendering UTF-8 text to Postscript (including OCR-B and Barcode)
- From: Matthias Apitz <apitzm oclc org>
- To: gtk-i18n-list gnome org
- Subject: rendering UTF-8 text to Postscript (including OCR-B and Barcode)
- Date: Fri, 30 Sep 2011 11:25:53 +0200
Hello,
I'm pretty new to pango/cairo, so forgive me if this is some kind of FAQ
or otherwise a stupid question...
I hacked together a small C-pgm to understand how pango and cairo could
be used for the issue in the Subject: and I'm able to render UTF-8 text,
including OCR-B (located in ~/.fonts/OCRB.pfb) to Postscript for
printing, see attachment. It's basically a call to
pango_layout_set_markup(layout, "normal and OCR on same line: <span font=\"" OCRB_FONT "\">ABC 0123456789</span>", -1);
The missing next challenge is to print as well a Barcode label, like the
OCR-B number.
Could this be done on the same <span font=...> way and are there any
free barcode fonts the most used barcode types?
Thanks in advance
matthias
--
Matthias Apitz
http://www.UnixArea.de/
People who hate Microsoft Windows use Linux but people who love UNIX use
FreeBSD.
#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
#define LINE_SIZE 10
#define TEXT_FONT "Monospace 6"
#define OCRB_FONT "OCRB 6"
void rendertext(cairo_t *cr, char *text);
void renderocrb(cairo_t *cr, char *text);
int main(int argc, char* argv[]) {
cairo_t *cr;
cairo_status_t status;
cairo_surface_t *surface;
char buf[128];
sprintf(buf, "<b>TEXT_FONT: [%s] LINE_SIZE: [%d], OCRB_FONT: [%s]</b>",
TEXT_FONT, LINE_SIZE, OCRB_FONT);
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 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, buf);
rendertext(cr, "");
rendertext(cr, "<i>Arabic</i> السلام عليكم ");
rendertext(cr, "<b>Bengali</b> (বাঙ্লা) ষাগতোম");
rendertext(cr, "<i><b>Greek</b></i> (Ελληνικά) Γειά σας");
rendertext(cr, "<u>Hebrew</u> שָׁלוֹם");
rendertext(cr, "<b>Japanese (日本語) こんにちは, コンニチハ </b>");
rendertext(cr, "Chinese (中文,普通话,汉语) 你好");
rendertext(cr, "Vietnamese (Tiếng Việt) Xin Chào");
rendertext(cr, "<span font=\"" OCRB_FONT "\">ABC 0123456789</span>");
rendertext(cr, "Español ¡Que vivan los sueños!");
rendertext(cr, "normal and OCR on same line: <span font=\"" OCRB_FONT "\">ABC 0123456789</span>");
cairo_show_page(cr);
cairo_ps_surface_dsc_comment (surface, "%%IncludeFeature: *PageSize A4");
cairo_destroy(cr);
cairo_surface_destroy(surface);
return 0;
}
static float line = 2*LINE_SIZE;
void rendertext(cairo_t *cr, char *text) {
PangoLayout *layout;
PangoFontDescription *desc;
line = line + LINE_SIZE;
layout = pango_cairo_create_layout(cr);
pango_layout_set_markup(layout, text, -1);
desc = pango_font_description_from_string( TEXT_FONT );
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);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]