~ubuntu-branches/ubuntu/hardy/ghostscript/hardy

« back to all changes in this revision

Viewing changes to src/gdevpdts.c

  • Committer: Bazaar Package Importer
  • Author(s): Till Kamppeter
  • Date: 2007-11-22 12:17:43 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20071122121743-cd70s3ypq0r243mp
Tags: 8.61.dfsg.1-0ubtuntu1
* New upstream release
  o Final 8.61 release
* debian/patches/09_ijs_krgb_support.dpatch: Adapted to upstream changes.
* debian/rules: Updated CUPS-related variables for "make install" calls.
* debian/rules: Remove /usr/include/ghostscript from the ghostscript
  package, they go into lings-dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
   San Rafael, CA  94903, U.S.A., +1(415)492-9861, for further information.
12
12
*/
13
13
 
14
 
/* $Id: gdevpdts.c 8022 2007-06-05 22:23:38Z giles $ */
 
14
/* $Id: gdevpdts.c 8265 2007-10-02 07:31:58Z ken $ */
15
15
/* Text state management for pdfwrite */
16
16
#include "math_.h"
17
17
#include "memory_.h"
21
21
#include "gdevpdtx.h"
22
22
#include "gdevpdtf.h"           /* for pdfont->FontType */
23
23
#include "gdevpdts.h"
 
24
#include "gdevpdtt.h"
24
25
 
25
26
/* ================ Types and structures ================ */
26
27
 
80
81
    gs_point line_start;
81
82
    gs_point out_pos;           /* output position */
82
83
};
83
 
private const pdf_text_state_t ts_default = {
 
84
static const pdf_text_state_t ts_default = {
84
85
    /* State as seen by client */
85
86
    { TEXT_STATE_VALUES_DEFAULT },      /* in */
86
87
    { 0, 0 },                   /* start */
109
110
 * direction, return <0 and do nothing.  (This is different from
110
111
 * pdf_append_chars.)  Requires pts->buffer.count_chars > 0.
111
112
 */
112
 
private int
 
113
static int
113
114
append_text_move(pdf_text_state_t *pts, floatp dw)
114
115
{
115
116
    int count = pts->buffer.count_moves;
143
144
/*
144
145
 * Set *pdist to the distance (dx,dy), in the space defined by *pmat.
145
146
 */
146
 
private int
 
147
static int
147
148
set_text_distance(gs_point *pdist, floatp dx, floatp dy, const gs_matrix *pmat)
148
149
{
149
150
    int code = gs_distance_transform_inverse(dx, dy, pmat, pdist);
170
171
/*
171
172
 * Test whether the transformation parts of two matrices are compatible.
172
173
 */
173
 
private bool
 
174
static bool
174
175
matrix_is_compatible(const gs_matrix *pmat1, const gs_matrix *pmat2)
175
176
{
176
177
    return (pmat2->xx == pmat1->xx && pmat2->xy == pmat1->xy &&
181
182
 * Try to handle a change of text position with TJ or a space
182
183
 * character.  If successful, return >=0, if not, return <0.
183
184
 */
184
 
private int
 
185
static int
185
186
add_text_delta_move(gx_device_pdf *pdev, const gs_matrix *pmat)
186
187
{
187
188
    pdf_text_state_t *const pts = pdev->text->text_state;
246
247
 * a Y translation, set use_leading so the next text string will be written
247
248
 * with ' rather than Tj; otherwise, write a Td command.
248
249
 */
249
 
private int
 
250
static int
250
251
pdf_set_text_matrix(gx_device_pdf * pdev)
251
252
{
252
253
    pdf_text_state_t *pts = pdev->text->text_state;
375
376
/*
376
377
 *  Flush text from buffer.
377
378
 */
378
 
private int
 
379
static int
379
380
flush_text_buffer(gx_device_pdf *pdev)
380
381
{
381
382
    pdf_text_state_t *pts = pdev->text->text_state;
421
422
/*
422
423
 * Transition from string context to text context.
423
424
 */
424
 
private int
 
425
static int
425
426
sync_text_state(gx_device_pdf *pdev)
426
427
{
427
428
    pdf_text_state_t *pts = pdev->text->text_state;
653
654
    pts->out_pos.y += wy;
654
655
    return 0;
655
656
}
 
657
 
 
658
/* Check a new piece of charpath text to see if its safe to combine
 
659
 * with a previous text operation using text rendering modes.
 
660
 */
 
661
bool pdf_compare_text_state_for_charpath(pdf_text_state_t *pts, gx_device_pdf *pdev, 
 
662
                                         gs_imager_state *pis, gs_font *font, 
 
663
                                         const gs_text_params_t *text)
 
664
{
 
665
    int code;
 
666
    float size;
 
667
    gs_matrix smat, tmat;
 
668
    struct pdf_font_resource_s *pdfont;
 
669
 
 
670
    /* check to ensure the new text has the same length as the saved text */
 
671
    if(text->size != pts->buffer.count_chars)
 
672
        return(false);
 
673
 
 
674
    if(font->FontType == ft_user_defined)
 
675
        return(false);
 
676
 
 
677
    /* check to ensure the new text has the same data as the saved text */
 
678
    if(memcmp(text->data.bytes, &pts->buffer.chars, text->size))
 
679
        return(false);
 
680
 
 
681
    /* See if the same font is in use by checking the attahced pdfont resource for
 
682
     * the currrent font and comparing with the saved text state
 
683
     */
 
684
    code = pdf_attached_font_resource(pdev, font, &pdfont, NULL, NULL, NULL, NULL);
 
685
    if(code < 0)
 
686
        return(false);
 
687
 
 
688
    if(!pdfont || pdfont != pts->in.pdfont)
 
689
        return(false);
 
690
 
 
691
    /* Check to see the new text starts at the same point as the saved text. 
 
692
     * NB! only check 2 decimal places, allow some slack in the match. This
 
693
     * still may prove to be too tight a requirement.
 
694
     */
 
695
    if((int)(pts->start.x * 100) != (int)(pis->current_point.x * 100) || 
 
696
        (int)(pts->start.y * 100) != (int)(pis->current_point.y * 100))
 
697
        return(false);
 
698
 
 
699
    size = pdf_calculate_text_size(pis, pdfont, &font->FontMatrix, &smat, &tmat, font, pdev);
 
700
 
 
701
    /* Finally, check the calculated size against the size stored in
 
702
     * the text state.
 
703
     */
 
704
    if(size != pts->in.size)
 
705
        return(false);
 
706
 
 
707
    return(true);
 
708
}
 
709
 
 
710
/* Add a render mode to the rendering mode of the current text.
 
711
 * mode 0 = fill
 
712
 * mode 1 = stroke
 
713
 * mode 2 = clip
 
714
 * If the modes are not compatible returns 0. NB currently only
 
715
 * a stroke rendering mode is supported.
 
716
 */
 
717
int pdf_modify_text_render_mode(pdf_text_state_t *pts, int render_mode)
 
718
{
 
719
    switch (pts->in.render_mode) {
 
720
        case 0:
 
721
            if (render_mode == 1) {
 
722
                pts->in.render_mode = 2;
 
723
                return(1);
 
724
            }
 
725
            break;
 
726
        case 1:
 
727
            if (render_mode == 1) 
 
728
                return(1);
 
729
            break;
 
730
        case 2:
 
731
            if (render_mode == 1) 
 
732
                return(1);
 
733
            break;
 
734
        case 3:
 
735
            if (render_mode == 1) {
 
736
                pts->in.render_mode = 1;
 
737
                return(1);
 
738
            }
 
739
            break;
 
740
        case 4:
 
741
            if (render_mode == 1) {
 
742
                pts->in.render_mode = 6;
 
743
                return(1);
 
744
            }
 
745
            break;
 
746
        case 5:
 
747
            if (render_mode == 1) 
 
748
                return(1);
 
749
            break;
 
750
        case 6:
 
751
            if (render_mode == 1) 
 
752
                return(1);
 
753
            break;
 
754
        case 7:
 
755
            if (render_mode == 1) {
 
756
                pts->in.render_mode = 5;
 
757
                return(1);
 
758
            }
 
759
            break;
 
760
        default:
 
761
            break;
 
762
    }
 
763
    return(0);
 
764
}