2008-07-14 01:15:55 +04:00
/* ps.c - Post Script output */
/*
libzint - the open source barcode library
2020-08-05 23:23:11 +03:00
Copyright ( C ) 2009 - 2020 Robin Stuart < rstuart114 @ gmail . com >
2013-05-16 21:26:38 +04:00
Redistribution and use in source and binary forms , with or without
modification , are permitted provided that the following conditions
are met :
2016-02-20 14:29:19 +03:00
1. Redistributions of source code must retain the above copyright
notice , this list of conditions and the following disclaimer .
2013-05-16 21:26:38 +04:00
2. Redistributions in binary form must reproduce the above copyright
notice , this list of conditions and the following disclaimer in the
2016-02-20 14:29:19 +03:00
documentation and / or other materials provided with the distribution .
2013-05-16 21:26:38 +04:00
3. Neither the name of the project nor the names of its contributors
may be used to endorse or promote products derived from this software
2016-02-20 14:29:19 +03:00
without specific prior written permission .
2013-05-16 21:26:38 +04:00
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS " AS IS " AND
ANY EXPRESS OR IMPLIED WARRANTIES , INCLUDING , BUT NOT LIMITED TO , THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED . IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT , INDIRECT , INCIDENTAL , SPECIAL , EXEMPLARY , OR CONSEQUENTIAL
DAMAGES ( INCLUDING , BUT NOT LIMITED TO , PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES ; LOSS OF USE , DATA , OR PROFITS ; OR BUSINESS INTERRUPTION )
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY , WHETHER IN CONTRACT , STRICT
LIABILITY , OR TORT ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY
2016-02-20 14:29:19 +03:00
OUT OF THE USE OF THIS SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF
2013-05-16 21:26:38 +04:00
SUCH DAMAGE .
2016-02-20 14:29:19 +03:00
*/
2019-12-19 03:37:55 +03:00
/* vim: set ts=4 sw=4 et : */
2008-07-14 01:15:55 +04:00
2010-05-23 09:02:08 +04:00
# include <locale.h>
2008-07-14 01:15:55 +04:00
# include <stdio.h>
2016-03-03 00:12:38 +03:00
# include <math.h>
2020-09-30 14:19:12 +03:00
# ifdef _MSC_VER
# include <malloc.h>
# endif
2008-07-14 01:15:55 +04:00
# include "common.h"
2020-09-30 14:19:12 +03:00
static void colour_to_pscolor ( int option , int colour , char * output ) {
2020-01-06 21:00:43 +03:00
strcpy ( output , " " ) ;
if ( ( option & CMYK_COLOUR ) = = 0 ) {
// Use RGB colour space
switch ( colour ) {
case 1 : // Cyan
strcat ( output , " 0.00 1.00 1.00 " ) ;
break ;
case 2 : // Blue
strcat ( output , " 0.00 0.00 1.00 " ) ;
break ;
case 3 : // Magenta
strcat ( output , " 1.00 0.00 1.00 " ) ;
break ;
case 4 : // Red
strcat ( output , " 1.00 0.00 0.00 " ) ;
break ;
case 5 : // Yellow
strcat ( output , " 1.00 1.00 0.00 " ) ;
break ;
case 6 : // Green
strcat ( output , " 0.00 1.00 0.00 " ) ;
break ;
2020-08-12 14:19:26 +03:00
case 8 : // White
strcat ( output , " 1.00 1.00 1.00 " ) ;
break ;
2020-01-06 21:00:43 +03:00
default : // Black
strcat ( output , " 0.00 0.00 0.00 " ) ;
break ;
}
strcat ( output , " setrgbcolor " ) ;
} else {
// Use CMYK colour space
switch ( colour ) {
case 1 : // Cyan
strcat ( output , " 1.00 0.00 0.00 0.00 " ) ;
break ;
case 2 : // Blue
strcat ( output , " 1.00 1.00 0.00 0.00 " ) ;
break ;
case 3 : // Magenta
strcat ( output , " 0.00 1.00 0.00 0.00 " ) ;
break ;
case 4 : // Red
strcat ( output , " 0.00 1.00 1.00 0.00 " ) ;
break ;
case 5 : // Yellow
strcat ( output , " 0.00 0.00 1.00 0.00 " ) ;
break ;
case 6 : // Green
strcat ( output , " 1.00 0.00 1.00 0.00 " ) ;
break ;
2020-08-12 14:19:26 +03:00
case 8 : // White
strcat ( output , " 0.00 0.00 0.00 0.00 " ) ;
break ;
2020-01-06 21:00:43 +03:00
default : // Black
strcat ( output , " 0.00 0.00 0.00 1.00 " ) ;
break ;
}
strcat ( output , " setcmykcolor " ) ;
}
}
2020-09-30 14:19:12 +03:00
STATIC_UNLESS_ZINT_TEST void ps_convert ( const unsigned char * string , unsigned char * ps_string ) {
const unsigned char * s ;
unsigned char * p = ps_string ;
for ( s = string ; * s ; s + + ) {
switch ( * s ) {
case ' ( ' :
case ' ) ' :
case ' \\ ' :
* p + + = ' \\ ' ;
* p + + = * s ;
break ;
case 0xC2 : /* See `to_iso8859_1()` in raster.c */
* p + + = * + + s ;
break ;
case 0xC3 :
* p + + = * + + s + 64 ;
break ;
default :
if ( * s < 0x80 ) {
* p + + = * s ;
}
break ;
}
}
* p = ' \0 ' ;
}
2019-12-19 03:37:55 +03:00
INTERNAL int ps_plot ( struct zint_symbol * symbol ) {
2016-02-20 14:29:19 +03:00
FILE * feps ;
int fgred , fggrn , fgblu , bgred , bggrn , bgblu ;
float red_ink , green_ink , blue_ink , red_paper , green_paper , blue_paper ;
2016-06-19 16:14:30 +03:00
float cyan_ink , magenta_ink , yellow_ink , black_ink ;
float cyan_paper , magenta_paper , yellow_paper , black_paper ;
2016-02-20 14:29:19 +03:00
int error_number = 0 ;
2018-06-10 11:16:18 +03:00
float ax , ay , bx , by , cx , cy , dx , dy , ex , ey , fx , fy ;
2020-10-26 15:21:43 +03:00
float previous_diameter ;
float radius , half_radius , half_sqrt3_radius ;
2020-01-06 21:00:43 +03:00
int colour_index , colour_rect_counter ;
char ps_color [ 30 ] ;
2020-08-03 09:37:27 +03:00
int draw_background = 1 ;
2018-06-10 11:16:18 +03:00
struct zint_vector_rect * rect ;
struct zint_vector_hexagon * hex ;
struct zint_vector_circle * circle ;
struct zint_vector_string * string ;
2016-02-20 14:29:19 +03:00
const char * locale = NULL ;
2020-09-30 14:19:12 +03:00
const char * font ;
int i , len ;
int ps_len = 0 ;
int iso_latin1 = 0 ;
# ifdef _MSC_VER
unsigned char * ps_string ;
# endif
2016-02-20 14:29:19 +03:00
2020-08-04 16:49:25 +03:00
if ( strlen ( symbol - > bgcolour ) > 6 ) {
if ( ( ctoi ( symbol - > bgcolour [ 6 ] ) = = 0 ) & & ( ctoi ( symbol - > bgcolour [ 7 ] ) = = 0 ) ) {
draw_background = 0 ;
}
}
2016-08-26 17:13:40 +03:00
if ( symbol - > output_options & BARCODE_STDOUT ) {
2016-02-20 14:29:19 +03:00
feps = stdout ;
} else {
feps = fopen ( symbol - > outfile , " w " ) ;
}
if ( feps = = NULL ) {
2017-07-27 18:01:53 +03:00
strcpy ( symbol - > errtxt , " 645: Could not open output file " ) ;
2016-02-20 14:29:19 +03:00
return ZINT_ERROR_FILE_ACCESS ;
}
locale = setlocale ( LC_ALL , " C " ) ;
fgred = ( 16 * ctoi ( symbol - > fgcolour [ 0 ] ) ) + ctoi ( symbol - > fgcolour [ 1 ] ) ;
fggrn = ( 16 * ctoi ( symbol - > fgcolour [ 2 ] ) ) + ctoi ( symbol - > fgcolour [ 3 ] ) ;
fgblu = ( 16 * ctoi ( symbol - > fgcolour [ 4 ] ) ) + ctoi ( symbol - > fgcolour [ 5 ] ) ;
bgred = ( 16 * ctoi ( symbol - > bgcolour [ 0 ] ) ) + ctoi ( symbol - > bgcolour [ 1 ] ) ;
bggrn = ( 16 * ctoi ( symbol - > bgcolour [ 2 ] ) ) + ctoi ( symbol - > bgcolour [ 3 ] ) ;
bgblu = ( 16 * ctoi ( symbol - > bgcolour [ 4 ] ) ) + ctoi ( symbol - > bgcolour [ 5 ] ) ;
2020-10-26 15:21:43 +03:00
red_ink = ( float ) ( fgred / 256.0 ) ;
green_ink = ( float ) ( fggrn / 256.0 ) ;
blue_ink = ( float ) ( fgblu / 256.0 ) ;
red_paper = ( float ) ( bgred / 256.0 ) ;
green_paper = ( float ) ( bggrn / 256.0 ) ;
blue_paper = ( float ) ( bgblu / 256.0 ) ;
2016-09-06 00:06:50 +03:00
2016-06-19 16:14:30 +03:00
/* Convert RGB to CMYK */
if ( red_ink > green_ink ) {
if ( blue_ink > red_ink ) {
2020-10-26 15:21:43 +03:00
black_ink = 1.0f - blue_ink ;
2016-06-19 16:14:30 +03:00
} else {
2020-10-26 15:21:43 +03:00
black_ink = 1.0f - red_ink ;
2016-06-19 16:14:30 +03:00
}
} else {
if ( blue_ink > red_ink ) {
2020-10-26 15:21:43 +03:00
black_ink = 1.0f - blue_ink ;
2016-06-19 16:14:30 +03:00
} else {
2020-10-26 15:21:43 +03:00
black_ink = 1.0f - green_ink ;
2016-06-19 16:14:30 +03:00
}
}
2020-10-26 15:21:43 +03:00
if ( black_ink < 1.0f ) {
cyan_ink = ( 1.0f - red_ink - black_ink ) / ( 1.0f - black_ink ) ;
magenta_ink = ( 1.0f - green_ink - black_ink ) / ( 1.0f - black_ink ) ;
yellow_ink = ( 1.0f - blue_ink - black_ink ) / ( 1.0f - black_ink ) ;
2016-06-19 16:14:30 +03:00
} else {
2020-10-26 15:21:43 +03:00
cyan_ink = 0.0f ;
magenta_ink = 0.0f ;
yellow_ink = 0.0f ;
2016-06-19 16:14:30 +03:00
}
2016-09-06 00:06:50 +03:00
2016-06-19 16:14:30 +03:00
if ( red_paper > green_paper ) {
if ( blue_paper > red_paper ) {
2020-10-26 15:21:43 +03:00
black_paper = 1.0f - blue_paper ;
2016-06-19 16:14:30 +03:00
} else {
2020-10-26 15:21:43 +03:00
black_paper = 1.0f - red_paper ;
2016-06-19 16:14:30 +03:00
}
} else {
if ( blue_paper > red_paper ) {
2020-10-26 15:21:43 +03:00
black_paper = 1.0f - blue_paper ;
2016-06-19 16:14:30 +03:00
} else {
2020-10-26 15:21:43 +03:00
black_paper = 1.0f - green_paper ;
2016-06-19 16:14:30 +03:00
}
}
2020-10-26 15:21:43 +03:00
if ( black_paper < 1.0f ) {
cyan_paper = ( 1.0f - red_paper - black_paper ) / ( 1.0f - black_paper ) ;
magenta_paper = ( 1.0f - green_paper - black_paper ) / ( 1.0f - black_paper ) ;
yellow_paper = ( 1.0f - blue_paper - black_paper ) / ( 1.0f - black_paper ) ;
2016-06-19 16:14:30 +03:00
} else {
2020-10-26 15:21:43 +03:00
cyan_paper = 0.0f ;
magenta_paper = 0.0f ;
yellow_paper = 0.0f ;
2016-06-19 16:14:30 +03:00
}
2016-02-20 14:29:19 +03:00
2020-09-30 14:19:12 +03:00
for ( i = 0 , len = ( int ) ustrlen ( symbol - > text ) ; i < len ; i + + ) {
switch ( symbol - > text [ i ] ) {
case ' ( ' :
case ' ) ' :
case ' \\ ' :
ps_len + = 2 ;
break ;
default :
if ( ! iso_latin1 & & symbol - > text [ i ] > = 0x80 ) {
iso_latin1 = 1 ;
}
ps_len + + ; /* Will overcount 2 byte UTF-8 chars */
break ;
}
}
# ifndef _MSC_VER
unsigned char ps_string [ ps_len + 1 ] ;
# else
ps_string = ( unsigned char * ) _alloca ( ps_len + 1 ) ;
# endif
2016-02-20 14:29:19 +03:00
/* Start writing the header */
fprintf ( feps , " %%!PS-Adobe-3.0 EPSF-3.0 \n " ) ;
2020-09-04 18:38:11 +03:00
if ( ZINT_VERSION_BUILD ) {
fprintf ( feps , " %%%%Creator: Zint %d.%d.%d.%d \n " , ZINT_VERSION_MAJOR , ZINT_VERSION_MINOR , ZINT_VERSION_RELEASE , ZINT_VERSION_BUILD ) ;
} else {
fprintf ( feps , " %%%%Creator: Zint %d.%d.%d \n " , ZINT_VERSION_MAJOR , ZINT_VERSION_MINOR , ZINT_VERSION_RELEASE ) ;
}
2018-06-10 11:16:18 +03:00
fprintf ( feps , " %%%%Title: Zint Generated Symbol \n " ) ;
2016-02-20 14:29:19 +03:00
fprintf ( feps , " %%%%Pages: 0 \n " ) ;
2018-06-10 11:16:18 +03:00
fprintf ( feps , " %%%%BoundingBox: 0 0 %d %d \n " , ( int ) ceil ( symbol - > vector - > width ) , ( int ) ceil ( symbol - > vector - > height ) ) ;
2016-02-20 14:29:19 +03:00
fprintf ( feps , " %%%%EndComments \n " ) ;
/* Definitions */
fprintf ( feps , " /TL { setlinewidth moveto lineto stroke } bind def \n " ) ;
2016-08-28 18:38:02 +03:00
fprintf ( feps , " /TD { newpath 0 360 arc fill } bind def \n " ) ;
2016-02-20 14:29:19 +03:00
fprintf ( feps , " /TH { 0 setlinewidth moveto lineto lineto lineto lineto lineto closepath fill } bind def \n " ) ;
fprintf ( feps , " /TB { 2 copy } bind def \n " ) ;
fprintf ( feps , " /TR { newpath 4 1 roll exch moveto 1 index 0 rlineto 0 exch rlineto neg 0 rlineto closepath fill } bind def \n " ) ;
fprintf ( feps , " /TE { pop pop } bind def \n " ) ;
fprintf ( feps , " newpath \n " ) ;
/* Now the actual representation */
2020-08-03 09:37:27 +03:00
//Background
if ( draw_background ) {
if ( ( symbol - > output_options & CMYK_COLOUR ) = = 0 ) {
fprintf ( feps , " %.2f %.2f %.2f setrgbcolor \n " , red_paper , green_paper , blue_paper ) ;
} else {
fprintf ( feps , " %.2f %.2f %.2f %.2f setcmykcolor \n " , cyan_paper , magenta_paper , yellow_paper , black_paper ) ;
}
fprintf ( feps , " %.2f 0.00 TB 0.00 %.2f TR \n " , symbol - > vector - > height , symbol - > vector - > width ) ;
fprintf ( feps , " TE \n " ) ;
2016-06-19 16:14:30 +03:00
}
2016-02-20 14:29:19 +03:00
2020-01-06 21:00:43 +03:00
if ( symbol - > symbology ! = BARCODE_ULTRA ) {
if ( ( symbol - > output_options & CMYK_COLOUR ) = = 0 ) {
fprintf ( feps , " %.2f %.2f %.2f setrgbcolor \n " , red_ink , green_ink , blue_ink ) ;
} else {
fprintf ( feps , " %.2f %.2f %.2f %.2f setcmykcolor \n " , cyan_ink , magenta_ink , yellow_ink , black_ink ) ;
}
2016-02-20 14:29:19 +03:00
}
2020-01-05 14:27:24 +03:00
2018-06-10 11:16:18 +03:00
// Rectangles
2020-01-06 21:00:43 +03:00
if ( symbol - > symbology = = BARCODE_ULTRA ) {
2020-08-12 14:19:26 +03:00
for ( colour_index = 0 ; colour_index < = 8 ; colour_index + + ) {
2020-01-06 21:00:43 +03:00
colour_rect_counter = 0 ;
rect = symbol - > vector - > rectangles ;
while ( rect ) {
if ( rect - > colour = = colour_index ) {
if ( colour_rect_counter = = 0 ) {
//Set new colour
colour_to_pscolor ( symbol - > output_options , colour_index , ps_color ) ;
fprintf ( feps , " %s \n " , ps_color ) ;
}
colour_rect_counter + + ;
fprintf ( feps , " %.2f %.2f TB %.2f %.2f TR \n " , rect - > height , ( symbol - > vector - > height - rect - > y ) - rect - > height , rect - > x , rect - > width ) ;
fprintf ( feps , " TE \n " ) ;
}
rect = rect - > next ;
}
}
} else {
rect = symbol - > vector - > rectangles ;
while ( rect ) {
fprintf ( feps , " %.2f %.2f TB %.2f %.2f TR \n " , rect - > height , ( symbol - > vector - > height - rect - > y ) - rect - > height , rect - > x , rect - > width ) ;
fprintf ( feps , " TE \n " ) ;
rect = rect - > next ;
}
2018-06-10 11:16:18 +03:00
}
2020-01-05 14:27:24 +03:00
2018-06-10 11:16:18 +03:00
// Hexagons
2020-10-26 15:21:43 +03:00
previous_diameter = radius = half_radius = half_sqrt3_radius = 0.0f ;
2018-06-10 11:16:18 +03:00
hex = symbol - > vector - > hexagons ;
while ( hex ) {
2020-10-26 15:21:43 +03:00
if ( previous_diameter ! = hex - > diameter ) {
previous_diameter = hex - > diameter ;
radius = ( float ) ( 0.5 * previous_diameter ) ;
half_radius = ( float ) ( 0.25 * previous_diameter ) ;
half_sqrt3_radius = ( float ) ( 0.43301270189221932338 * previous_diameter ) ;
}
2020-08-05 23:23:11 +03:00
if ( ( hex - > rotation = = 0 ) | | ( hex - > rotation = = 180 ) ) {
2020-10-26 15:21:43 +03:00
ay = ( symbol - > vector - > height - hex - > y ) + radius ;
by = ( symbol - > vector - > height - hex - > y ) + half_radius ;
cy = ( symbol - > vector - > height - hex - > y ) - half_radius ;
dy = ( symbol - > vector - > height - hex - > y ) - radius ;
ey = ( symbol - > vector - > height - hex - > y ) - half_radius ;
fy = ( symbol - > vector - > height - hex - > y ) + half_radius ;
2020-08-05 23:23:11 +03:00
ax = hex - > x ;
2020-10-26 15:21:43 +03:00
bx = hex - > x + half_sqrt3_radius ;
cx = hex - > x + half_sqrt3_radius ;
2020-08-05 23:23:11 +03:00
dx = hex - > x ;
2020-10-26 15:21:43 +03:00
ex = hex - > x - half_sqrt3_radius ;
fx = hex - > x - half_sqrt3_radius ;
2020-08-05 23:23:11 +03:00
} else {
ay = ( symbol - > vector - > height - hex - > y ) ;
2020-10-26 15:21:43 +03:00
by = ( symbol - > vector - > height - hex - > y ) + half_sqrt3_radius ;
cy = ( symbol - > vector - > height - hex - > y ) + half_sqrt3_radius ;
2020-08-05 23:23:11 +03:00
dy = ( symbol - > vector - > height - hex - > y ) ;
2020-10-26 15:21:43 +03:00
ey = ( symbol - > vector - > height - hex - > y ) - half_sqrt3_radius ;
fy = ( symbol - > vector - > height - hex - > y ) - half_sqrt3_radius ;
ax = hex - > x - radius ;
bx = hex - > x - half_radius ;
cx = hex - > x + half_radius ;
dx = hex - > x + radius ;
ex = hex - > x + half_radius ;
fx = hex - > x - half_radius ;
2020-08-05 23:23:11 +03:00
}
2018-06-10 11:16:18 +03:00
fprintf ( feps , " %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f TH \n " , ax , ay , bx , by , cx , cy , dx , dy , ex , ey , fx , fy ) ;
hex = hex - > next ;
}
2020-01-05 14:27:24 +03:00
2018-06-10 11:16:18 +03:00
// Circles
2020-10-26 15:21:43 +03:00
previous_diameter = radius = 0.0f ;
2018-06-10 11:16:18 +03:00
circle = symbol - > vector - > circles ;
while ( circle ) {
2020-10-26 15:21:43 +03:00
if ( previous_diameter ! = circle - > diameter ) {
previous_diameter = circle - > diameter ;
radius = ( float ) ( 0.5 * previous_diameter ) ;
}
2018-06-10 11:16:18 +03:00
if ( circle - > colour ) {
// A 'white' circle
2016-06-19 16:14:30 +03:00
if ( ( symbol - > output_options & CMYK_COLOUR ) = = 0 ) {
2018-06-10 11:16:18 +03:00
fprintf ( feps , " %.2f %.2f %.2f setrgbcolor \n " , red_paper , green_paper , blue_paper ) ;
2016-06-19 16:14:30 +03:00
} else {
2018-06-10 11:16:18 +03:00
fprintf ( feps , " %.2f %.2f %.2f %.2f setcmykcolor \n " , cyan_paper , magenta_paper , yellow_paper , black_paper ) ;
2016-02-20 14:29:19 +03:00
}
2020-10-26 15:21:43 +03:00
fprintf ( feps , " %.2f %.2f %.2f TD \n " , circle - > x , ( symbol - > vector - > height - circle - > y ) , radius ) ;
2018-06-10 11:16:18 +03:00
if ( circle - > next ) {
2016-08-28 18:38:02 +03:00
if ( ( symbol - > output_options & CMYK_COLOUR ) = = 0 ) {
fprintf ( feps , " %.2f %.2f %.2f setrgbcolor \n " , red_ink , green_ink , blue_ink ) ;
} else {
fprintf ( feps , " %.2f %.2f %.2f %.2f setcmykcolor \n " , cyan_ink , magenta_ink , yellow_ink , black_ink ) ;
}
}
2016-06-19 16:14:30 +03:00
} else {
2018-06-10 11:16:18 +03:00
// A 'black' circle
2020-10-26 15:21:43 +03:00
fprintf ( feps , " %.2f %.2f %.2f TD \n " , circle - > x , ( symbol - > vector - > height - circle - > y ) , radius ) ;
2016-06-19 13:59:09 +03:00
}
2018-06-10 11:16:18 +03:00
circle = circle - > next ;
2016-06-19 13:59:09 +03:00
}
2020-01-05 14:27:24 +03:00
2018-06-10 11:16:18 +03:00
// Text
2020-09-30 14:19:12 +03:00
2018-06-10 11:16:18 +03:00
string = symbol - > vector - > strings ;
2020-08-05 23:23:11 +03:00
2020-09-30 14:19:12 +03:00
if ( string ) {
if ( ( symbol - > output_options & BOLD_TEXT ) & & ( ! is_extendable ( symbol - > symbology ) | | ( symbol - > output_options & SMALL_TEXT ) ) ) {
font = " Helvetica-Bold " ;
} else {
font = " Helvetica " ;
}
if ( iso_latin1 ) { /* Change encoding to ISO 8859-1, see Postscript Language Reference Manual 2nd Edition Example 5.6 */
fprintf ( feps , " /%s findfont \n " , font ) ;
fprintf ( feps , " dup length dict begin \n " ) ;
fprintf ( feps , " {1 index /FID ne {def} {pop pop} ifelse} forall \n " ) ;
fprintf ( feps , " /Encoding ISOLatin1Encoding def \n " ) ;
fprintf ( feps , " currentdict \n " ) ;
fprintf ( feps , " end \n " ) ;
fprintf ( feps , " /Helvetica-ISOLatin1 exch definefont pop \n " ) ;
font = " Helvetica-ISOLatin1 " ;
}
2021-02-11 01:37:59 +03:00
do {
ps_convert ( string - > text , ps_string ) ;
fprintf ( feps , " matrix currentmatrix \n " ) ;
fprintf ( feps , " /%s findfont \n " , font ) ;
fprintf ( feps , " %.2f scalefont setfont \n " , string - > fsize ) ;
fprintf ( feps , " 0 0 moveto %.2f %.2f translate 0.00 rotate 0 0 moveto \n " , string - > x , ( symbol - > vector - > height - string - > y ) ) ;
if ( string - > halign = = 0 | | string - > halign = = 2 ) { /* Need width for middle or right align */
fprintf ( feps , " (%s) stringwidth \n " , ps_string ) ;
}
if ( string - > rotation ! = 0 ) {
fprintf ( feps , " gsave \n " ) ;
fprintf ( feps , " %d rotate \n " , 360 - string - > rotation ) ;
}
if ( string - > halign = = 0 | | string - > halign = = 2 ) {
fprintf ( feps , " pop \n " ) ;
fprintf ( feps , " %s 0 rmoveto \n " , string - > halign = = 2 ? " neg " : " -2 div " ) ;
}
fprintf ( feps , " (%s) show \n " , ps_string ) ;
if ( string - > rotation ! = 0 ) {
fprintf ( feps , " grestore \n " ) ;
}
fprintf ( feps , " setmatrix \n " ) ;
string = string - > next ;
} while ( string ) ;
2016-02-20 14:29:19 +03:00
}
2020-01-05 14:27:24 +03:00
//fprintf(feps, "\nshowpage\n");
2016-02-20 14:29:19 +03:00
if ( symbol - > output_options & BARCODE_STDOUT ) {
fflush ( feps ) ;
} else {
fclose ( feps ) ;
}
if ( locale )
setlocale ( LC_ALL , locale ) ;
return error_number ;
2008-07-14 01:15:55 +04:00
}