Exemple #1
0
/* retrieve the current pcl state and initialize pcl */
static int
pxPassthrough_init(px_state_t * pxs)
{
    int code;

    if (gs_debug_c('i'))
        dmprintf(pxs->memory, "passthrough: initializing global pcl state\n");
    global_pcs = pcl_get_gstate(pxs->pcls);

    /* default to pcl5c */
    global_pcs->personality = 0;
    /* for now we do not support intepolation in XL passthrough mode. */
    global_pcs->interpolate = false;
    /* we don't see a nice way to support the following options with
       passthrough at this time (NB) */
    global_pcs->page_set_on_command_line = false;
    global_pcs->res_set_on_command_line = false;
    global_pcs->high_level_device = false;

    {
        char buf[100];
        int ret;
        stream_cursor_read r;

        ret =
            gs_sprintf(buf,
                    "@PJL SET PAPERLENGTH = %d\n@PJL SET PAPERWIDTH = %d\n",
                    (int)(pxs->media_dims.y * 10 + .5),
                    (int)(pxs->media_dims.x * 10 + .5));
        r.ptr = (byte *) buf - 1;
        r.limit = (byte *) buf + ret - 1;
        pjl_proc_process(pxs->pjls, &r);
    }

    /* do an initial reset to set up a permanent reset.  The
       motivation here is to avoid tracking down a slew of memory
       leaks */
    global_pcs->xfm_state.paper_size = pcl_get_default_paper(global_pcs);
    pcl_do_resets(global_pcs, pcl_reset_initial);
    pcl_do_resets(global_pcs, pcl_reset_permanent);

    /* initialize pcl and install xl's page device in pcl's state */
    pcl_init_state(global_pcs, pxs->memory);
    code = gs_setdevice_no_erase(global_pcs->pgs, gs_currentdevice(pxs->pgs));
    if (code < 0)
        return code;

    /* yet another reset with the new page device */
    global_pcs->xfm_state.paper_size = pcl_get_default_paper(global_pcs);
    pcl_do_resets(global_pcs, pcl_reset_initial);
    /* set the parser state and initialize the pcl parser */
    global_pcl_parser_state.definitions = global_pcs->pcl_commands;
    global_pcl_parser_state.hpgl_parser_state = &global_gl_parser_state;
    pcl_process_init(&global_pcl_parser_state);
    /* default 600 to match XL allow PCL to override */
    global_pcs->uom_cp = 7200L / 600L;
    gs_setgray(global_pcs->pgs, 0);
    return 0;
}
static char *
err_code_string(int err_code)
  {
  if ((err_code<EMOTOR)||(err_code>ESERIAL))
    {
    gs_sprintf(err_buffer,"err_code out of range: %d",err_code);
    return err_buffer;
    }
  return errmsg[err_code];
  }
Exemple #3
0
static void
gx_print_segment(const gs_memory_t *mem, const segment * pseg)
{
    double px = fixed2float(pseg->pt.x);
    double py = fixed2float(pseg->pt.y);
    char out[80];

    gs_sprintf(out, "0x%lx<0x%lx,0x%lx>:%u",
         (ulong) pseg, (ulong) pseg->prev, (ulong) pseg->next, pseg->notes);
    switch (pseg->type) {
        case s_start:{
                const subpath *const psub = (const subpath *)pseg;

                dmprintf5(mem, "   %1.4f %1.4f moveto\t%% %s #curves=%d last=0x%lx\n",
                          px, py, out, psub->curve_count, (ulong) psub->last);
                break;
            }
        case s_curve:{
                const curve_segment *const pcur = (const curve_segment *)pseg;

                dmprintf7(mem, "   %1.4f %1.4f %1.4f %1.4f %1.4f %1.4f curveto\t%% %s\n",
                          fixed2float(pcur->p1.x), fixed2float(pcur->p1.y),
                          fixed2float(pcur->p2.x), fixed2float(pcur->p2.y),
                          px, py, out);
                break;
            }
        case s_line:
            dmprintf3(mem, "   %1.4f %1.4f lineto\t%% %s\n", px, py, out);
            break;
        case s_gap:
            dmprintf3(mem, "   %1.4f %1.4f gapto\t%% %s\n", px, py, out);
            break;
        case s_dash:{
                const dash_segment *const pd = (const dash_segment *)pseg;

                dmprintf5(mem, "   %1.4f %1.4f %1.4f  %1.4f dash\t%% %s\n",
                          fixed2float(pd->pt.x), fixed2float(pd->pt.y),
                          fixed2float(pd->tangent.x),fixed2float(pd->tangent.y),
                          out);
                break;
            }
        case s_line_close:{
                const line_close_segment *const plc =
                (const line_close_segment *)pseg;

                dmprintf4(mem, "   closepath\t%% %s %1.4f %1.4f 0x%lx\n",
                          out, px, py, (ulong) (plc->sub));
                break;
            }
        default:
            dmprintf4(mem, "   %1.4f %1.4f <type 0x%x>\t%% %s\n",
                      px, py, pseg->type, out);
    }
}
Exemple #4
0
/* error callback for jbig2 decoder */
static int
s_jbig2decode_error(void *error_callback_data, const char *msg, Jbig2Severity severity,
               int32_t seg_idx)
{
    stream_jbig2decode_state *const state =
        (stream_jbig2decode_state *) error_callback_data;
    const char *type;
    char segment[22];
    int code = 0;

    switch (severity) {
        case JBIG2_SEVERITY_DEBUG:
            type = "DEBUG"; break;;
        case JBIG2_SEVERITY_INFO:
            type = "info"; break;;
        case JBIG2_SEVERITY_WARNING:
            type = "WARNING"; break;;
        case JBIG2_SEVERITY_FATAL:
            type = "FATAL ERROR decoding image:";
            /* pass the fatal error upstream if possible */
            code = gs_error_ioerror;
            if (state != NULL) state->error = code;
            break;;
        default: type = "unknown message:"; break;;
    }
    if (seg_idx == -1) segment[0] = '\0';
    else gs_sprintf(segment, "(segment 0x%02x)", seg_idx);

    if (state)
    {
        if (severity == JBIG2_SEVERITY_FATAL) {
            dmlprintf3(state->memory, "jbig2dec %s %s %s\n", type, msg, segment);
        } else {
            if_debug3m('w', state->memory, "[w] jbig2dec %s %s %s\n", type, msg, segment);
        }
    }
    else
    {
/*
        FIXME error_callback_data should be updated so that jbig2_ctx_new is not called
        with a NULL argument (see jbig2.h) and we never reach here with a NULL state
*/
        if (severity == JBIG2_SEVERITY_FATAL) {
            dlprintf3("jbig2dec %s %s %s\n", type, msg, segment);
        } else {
            if_debug3('w', "[w] jbig2dec %s %s %s\n", type, msg, segment);
        }
    }

    return code;
}
Exemple #5
0
/* Encode a character. */
gs_glyph
zfont_encode_char(gs_font *pfont, gs_char chr, gs_glyph_space_t gspace)
{
    font_data *pdata = pfont_data(pfont);
    const ref *pencoding = &pdata->Encoding;
    ulong index = chr;	/* work around VAX widening bug */
    ref cname;
    int code = array_get(pfont->memory, pencoding, (long)index, &cname);

    if (code < 0 || !r_has_type(&cname, t_name))
        return gs_no_glyph;
    if (pfont->FontType == ft_user_defined && r_type(&pdata->BuildGlyph) == t_null) {
        ref nsref, tname;

        name_string_ref(pfont->memory, &cname, &nsref);
        if (r_size(&nsref) == 7 &&
            !memcmp(nsref.value.const_bytes, ".notdef", r_size(&nsref))) {
            /* A special support for high level devices.
               They need a glyph name but the font doesn't provide one
               due to an instandard BuildChar.
               Such fonts don't conform to PLRM section 5.3.7,
               but we've got real examples that we want to handle (Bug 686982).
               Construct a name here.
               Low level devices don't pass here, because regular PS interpretation
               doesn't need such names.
            */
            char buf[20];
            int code;

            if (gspace == GLYPH_SPACE_NOGEN)
                return gs_no_glyph;
            gs_sprintf(buf, "j%ld", chr); /* 'j' is arbutrary. */
            code = name_ref(pfont->memory, (const byte *)buf, strlen(buf), &tname, 1);
            if (code < 0) {
                /* Can't propagate the error due to interface limitation,
                   return with .notdef */
            } else
                cname = tname;
        }
    }
    return (gs_glyph)name_index(pfont->memory, &cname);
}
Exemple #6
0
/* Get the name of a glyph. */
static int
zfont_glyph_name(gs_font *font, gs_glyph index, gs_const_string *pstr)
{
    ref nref, sref;

    if (index >= gs_min_cid_glyph) {	/* Fabricate a numeric name. */
        char cid_name[sizeof(gs_glyph) * 3 + 1];
        int code;

        gs_sprintf(cid_name, "%lu", (ulong) index);
        code = name_ref(font->memory, (const byte *)cid_name, strlen(cid_name),
                        &nref, 1);
        if (code < 0)
            return code;
    } else
        name_index_ref(font->memory, index, &nref);
    name_string_ref(font->memory, &nref, &sref);
    pstr->data = sref.value.const_bytes;
    pstr->size = r_size(&sref);
    return 0;
}
Exemple #7
0
static int
xps_true_callback_glyph_name(gs_font *pfont, gs_glyph glyph, gs_const_string *pstr)
{
    /* This function is copied verbatim from plfont.c */

    int table_length;
    int table_offset;

    ulong format;
    uint numGlyphs;
    uint glyph_name_index;
    const byte *postp; /* post table pointer */

    /* guess if the font type is not truetype */
    if ( pfont->FontType != ft_TrueType )
    {
        glyph -= 29;
        if ( glyph >= 0 && glyph < 258 )
        {
            pstr->data = (byte*) pl_mac_names[glyph];
            pstr->size = strlen((char*)pstr->data);
            return 0;
        }
        else
        {
            return gs_throw1(-1, "glyph index %lu out of range", (ulong)glyph);
        }
    }

    table_offset = xps_find_sfnt_table((xps_font_t*)pfont->client_data, "post", &table_length);

    /* no post table */
    if (table_offset < 0)
        return gs_throw(-1, "no post table");

    /* this shoudn't happen but... */
    if ( table_length == 0 )
        return gs_throw(-1, "zero-size post table");

    ((gs_font_type42 *)pfont)->data.string_proc((gs_font_type42 *)pfont,
                                                table_offset, table_length, &postp);
    format = u32(postp);

    /* Format 1.0 (mac encoding) is a simple table see the TT spec.
     * We don't implement this because we don't see it in practice.
     * Format 2.5 is deprecated.
     * Format 3.0 means that there is no post data in the font file.
     * We see this a lot but can't do much about it.
     * The only format we support is 2.0.
     */
    if ( format != 0x20000 )
    {
        /* Invent a name if we don't know the table format. */
        char buf[32];
        gs_sprintf(buf, "glyph%d", (int)glyph);
        pstr->data = (byte*)buf;
        pstr->size = strlen((char*)pstr->data);
        return 0;
    }

    /* skip over the post header */
    numGlyphs = u16(postp + 32);
    if ( glyph < 0 || glyph > numGlyphs - 1)
    {
        return gs_throw1(-1, "glyph index %lu out of range", (ulong)glyph);
    }

    /* glyph name index starts at post + 34 each entry is 2 bytes */
    glyph_name_index = u16(postp + 34 + (glyph * 2));

    /* this shouldn't happen */
    if ( glyph_name_index < 0 && glyph_name_index > 0x7fff )
        return gs_throw(-1, "post table format error");

    /* mac easy */
    if ( glyph_name_index < 258 )
    {
        // dmprintf2(pfont->memory, "glyph name (mac) %d = %s\n", glyph, pl_mac_names[glyph_name_index]);
        pstr->data = (byte*) pl_mac_names[glyph_name_index];
        pstr->size = strlen((char*)pstr->data);
        return 0;
    }

    /* not mac */
    else
    {
        byte *mydata;

        /* and here's the tricky part */
        const byte *pascal_stringp = postp + 34 + (numGlyphs * 2);

        /* 0 - 257 lives in the mac table above */
        glyph_name_index -= 258;

        /* The string we want is the index'th pascal string,
         * so we "hop" to each length byte "index" times. */
        while (glyph_name_index > 0)
        {
            pascal_stringp += ((int)(*pascal_stringp)+1);
            glyph_name_index--;
        }

        /* length byte */
        pstr->size = (int)(*pascal_stringp);

        /* + 1 is for the length byte */
        pstr->data = pascal_stringp + 1;

        /* sanity check */
        if ( pstr->data + pstr->size > postp + table_length || pstr->data - 1 < postp)
            return gs_throw(-1, "data out of range");

        /* sigh - we have to allocate a copy of the data - by the
         * time a high level device makes use of it the font data
         * may be freed. This is a necessary leak. */
        mydata = gs_alloc_bytes(pfont->memory, pstr->size + 1, "glyph to name");
        if ( mydata == 0 )
            return -1;
        memcpy(mydata, pascal_stringp + 1, pstr->size);
        pstr->data = mydata;

        mydata[pstr->size] = 0;

        return 0;
    }
}
/* Send the page to the printer.  For speed, compress each scan line,
   since computer-to-printer communication time is often a bottleneck. */
static int
npdl_print_page_copies(gx_device_printer * pdev, FILE * prn_stream, int num_copies)
{
    gx_device_lprn *const lprn = (gx_device_lprn *) pdev;
    int line_size = gdev_prn_raster(pdev);
    int x_dpi = (int)(pdev->x_pixels_per_inch);
    char paper_command[5];
    int code;
    int maxY = lprn->BlockLine / lprn->nBh * lprn->nBh;

    if (!(lprn->CompBuf = gs_malloc(pdev->memory->non_gc_memory, line_size * maxY, sizeof(byte), "npdl_print_page_copies(CompBuf)")))
        return_error(gs_error_VMerror);

        /* Initialize printer */
    if (pdev->PageCount == 0) {

      /* Initialize printer */
      fputs("\033c1", prn_stream);               /* Software Reset */
      fputs("\034d240.", prn_stream);            /* Page Printer Mode */

        /* Check paper size */
        switch (npdl_get_paper_size((gx_device *) pdev)) {
            case PAPER_SIZE_POSTCARD:
                gs_sprintf(paper_command, "PC");
                break;
            case PAPER_SIZE_A5:
                gs_sprintf(paper_command, "A5");
                break;
            case PAPER_SIZE_A4:
                gs_sprintf(paper_command, "A4");
                break;
            case PAPER_SIZE_A3:
                gs_sprintf(paper_command, "A3");
                break;
            case PAPER_SIZE_B5:
                gs_sprintf(paper_command, "B5");
                break;
            case PAPER_SIZE_B4:
                gs_sprintf(paper_command, "B4");
                break;
            case PAPER_SIZE_LETTER:
                gs_sprintf(paper_command, "LT");
                break;
            case PAPER_SIZE_ENV4:
                gs_sprintf(paper_command, "ENV4");
                break;
            case PAPER_SIZE_BPOSTCARD:
                gs_sprintf(paper_command, "UPPC");
                break;
        }

        if (lprn->ManualFeed) {
        fprintf(prn_stream, "\034f%cM0.",
                (pdev->MediaSize[0] > pdev->MediaSize[1]) ? 'L' : 'P');
        /* Page Orientation  P: Portrait, L: Landscape */
        } else {
        fprintf(prn_stream, "\034f%c%s.",
                (pdev->MediaSize[0] > pdev->MediaSize[1]) ? 'L' : 'P',
        /* Page Orientation  P: Portrait, L: Landscape */
                paper_command);	/* Paper Size */
        }

        fprintf(prn_stream, "\034<1/%d,i.", x_dpi);	/* Image Resolution */

        /* Duplex Setting */
        if (pdev->Duplex_set > 0) {
            if (pdev->Duplex) {
                if (lprn->Tumble == 0)
                  fprintf(prn_stream, "\034'B,,1,0.");
                else
                  fprintf(prn_stream, "\034'B,,2,0.");
            } else
              fprintf(prn_stream, "\034'S,,,0.");
        }
    }

    if (num_copies > 99)
       num_copies = 99;
    fprintf(prn_stream, "\034x%d.", num_copies);

    lprn->initialized = false;

    if (lprn->NegativePrint) {
        fprintf(prn_stream, "\034e0,0.");	/* move to (0, 0) */
        fprintf(prn_stream, "\034Y");	/* goto figure mode */
        fprintf(prn_stream, "SU1,%d,0;", (int)pdev->x_pixels_per_inch);
        /* Setting Printer Unit */
        fprintf(prn_stream, "SG0,0;");	/* select black color */
        fprintf(prn_stream, "NP;");	/* begin path */
        fprintf(prn_stream, "PA%d,0,%d,%d,0,%d;",
                pdev->width, pdev->width, pdev->height, pdev->height);
        /* draw rectangle */
        fprintf(prn_stream, "CP");	/* close path */
        fprintf(prn_stream, "EP;");	/* end path */
        fprintf(prn_stream, "FL0;");	/* fill path */
        fprintf(prn_stream, "\034Z");	/* end of figure mode */
        fprintf(prn_stream, "\034\"R.");	/* `R'eplace Mode */
    }
    code = lprn_print_image(pdev, prn_stream);
    if (code < 0)
        return code;

    /* Form Feed */
    fputs("\014", prn_stream);

    gs_free(pdev->memory->non_gc_memory, lprn->CompBuf, line_size * maxY, sizeof(byte), "npdl_print_page_copies(CompBuf)");
    return 0;
}
static void
write_main_dictionary(gs_fapi_font * a_fapi_font, WRF_output * a_output,
                      int Write_CharStrings)
{
    int i;

    WRF_wstring(a_fapi_font->memory, a_output, "5 dict begin\n");

    WRF_wstring(a_fapi_font->memory, a_output, "/FontType 1 def\n");

    WRF_wstring(a_fapi_font->memory, a_output, "/FontMatrix [");
    for (i = 0; i < 6; i++) {
        WRF_wfloat(a_fapi_font->memory, a_output,
                   a_fapi_font->get_float(a_fapi_font,
                                          gs_fapi_font_feature_FontMatrix,
                                          i));
        WRF_wbyte(a_fapi_font->memory, a_output, (byte) (i == 5 ? ']' : ' '));
    }
    WRF_wbyte(a_fapi_font->memory, a_output, '\n');

    /* For now, specify standard encoding - I think GS will pass glyph indices so doesn't matter. */
    WRF_wstring(a_fapi_font->memory, a_output, "/Encoding StandardEncoding def\n");

    WRF_wstring(a_fapi_font->memory, a_output, "/FontBBox {");
    for (i = 0; i < 4; i++) {
        short x =
            a_fapi_font->get_word(a_fapi_font, gs_fapi_font_feature_FontBBox,
                                  i);
        WRF_wint(a_fapi_font->memory, a_output, x);
        WRF_wbyte(a_fapi_font->memory, a_output, (byte) (i == 3 ? '}' : ' '));
    }
    WRF_wbyte(a_fapi_font->memory, a_output, '\n');
    if (is_MM_font(a_fapi_font)) {
        short x, x2;
        float x1;
        uint i, j, entries;
        char Buffer[255];

        entries = 0;
        x = a_fapi_font->get_word(a_fapi_font,
                                  gs_fapi_font_feature_BlendAxisTypes_count,
                                  0);
        if (x)
            entries++;
        x = a_fapi_font->get_word(a_fapi_font,
                                  gs_fapi_font_feature_BlendDesignPositionsArrays_count,
                                  0);
        if (x)
            entries++;
        x = a_fapi_font->get_word(a_fapi_font,
                                  gs_fapi_font_feature_BlendDesignMapArrays_count,
                                  0);
        if (x)
            entries++;

        gs_sprintf(Buffer, "/FontInfo %d dict dup begin\n", entries);
        WRF_wstring(a_fapi_font->memory, a_output, Buffer);
        x = a_fapi_font->get_word(a_fapi_font,
                                  gs_fapi_font_feature_BlendAxisTypes_count,
                                  0);
        if (x) {
            WRF_wstring(a_fapi_font->memory, a_output, "/BlendAxisTypes [");
            for (i = 0; i < x; i++) {
                WRF_wstring(a_fapi_font->memory, a_output, " /");
                a_fapi_font->get_name(a_fapi_font,
                                      gs_fapi_font_feature_BlendAxisTypes, i,
                                      (char *)&Buffer, 255);
                WRF_wstring(a_fapi_font->memory, a_output, Buffer);
            }
            WRF_wstring(a_fapi_font->memory, a_output, "] def\n");
        }
        x = a_fapi_font->get_word(a_fapi_font,
                                  gs_fapi_font_feature_BlendDesignPositionsArrays_count,
                                  0);
        if (x) {
            WRF_wstring(a_fapi_font->memory, a_output, "/BlendDesignPositions [");
            x2 = a_fapi_font->get_word(a_fapi_font,
                                       gs_fapi_font_feature_BlendAxisTypes_count,
                                       0);
            for (i = 0; i < x; i++) {
                WRF_wstring(a_fapi_font->memory, a_output, "[");
                for (j = 0; j < x2; j++) {
                    x1 = a_fapi_font->get_float(a_fapi_font,
                                                gs_fapi_font_feature_BlendDesignPositionsArrayValue,
                                                i * 8 + j);
                    gs_sprintf(Buffer, "%f ", x1);
                    WRF_wstring(a_fapi_font->memory, a_output, Buffer);
                }
                WRF_wstring(a_fapi_font->memory, a_output, "]");
            }
            WRF_wstring(a_fapi_font->memory, a_output, "] def\n");
        }
        x = a_fapi_font->get_word(a_fapi_font,
                                  gs_fapi_font_feature_BlendDesignMapArrays_count,
                                  0);
        if (x) {
            WRF_wstring(a_fapi_font->memory, a_output, "/BlendDesignMap [");
            for (i = 0; i < x; i++) {
                x2 = a_fapi_font->get_word(a_fapi_font,
                                           gs_fapi_font_feature_BlendDesignMapSubArrays_count,
                                           i);
                WRF_wstring(a_fapi_font->memory, a_output, "[");
                for (j = 0; j < x2; j++) {
                    WRF_wstring(a_fapi_font->memory, a_output, "[");
                    x1 = a_fapi_font->get_float(a_fapi_font,
                                                gs_fapi_font_feature_BlendDesignPositionsArrayValue,
                                                i * 64 + j * 64);
                    gs_sprintf(Buffer, "%f ", x1);
                    WRF_wstring(a_fapi_font->memory, a_output, Buffer);
                    x1 = a_fapi_font->get_float(a_fapi_font,
                                                gs_fapi_font_feature_BlendDesignPositionsArrayValue,
                                                i * 64 + j * 64 + 1);
                    gs_sprintf(Buffer, "%f ", x1);
                    WRF_wstring(a_fapi_font->memory, a_output, Buffer);
                    WRF_wstring(a_fapi_font->memory, a_output, "]");
                }
                WRF_wstring(a_fapi_font->memory, a_output, "]");
            }
            WRF_wstring(a_fapi_font->memory, a_output, "] def\n");
        }
        WRF_wstring(a_fapi_font->memory, a_output, "end readonly def\n");

        /* Previously we tried to write $Blend twice - the "real" one from the font,
         * and the boiler plate one below.
         * For now, I assume there was a good reason for including the second, but it may
         * be because the "get_proc" method below was missing the code to handle PS name
         * objects.
         */
        if ((x =
             a_fapi_font->get_word(a_fapi_font,
                                   gs_fapi_font_feature_DollarBlend_length,
                                   0)) > 0) {
            WRF_wstring(a_fapi_font->memory, a_output, "/$Blend {");

            if (a_output->m_count)
                a_output->m_count += x;
            x = a_fapi_font->get_proc(a_fapi_font,
                                      gs_fapi_font_feature_DollarBlend, 0,
                                      (char *)a_output->m_pos);
            if (a_output->m_pos)
                a_output->m_pos += x;
            WRF_wstring(a_fapi_font->memory, a_output, "} def\n");
        } else {
            WRF_wstring(a_fapi_font->memory, a_output,
                        "/$Blend {0.1 mul exch 0.45 mul add exch 0.17 mul add add} def\n");
        }
        WRF_wstring(a_fapi_font->memory, a_output, "/WeightVector [");
        x = a_fapi_font->get_word(a_fapi_font,
                                  gs_fapi_font_feature_WeightVector_count, 0);
        for (i = 0; i < x; i++) {
            x1 = a_fapi_font->get_float(a_fapi_font,
                                        gs_fapi_font_feature_WeightVector, i);
            gs_sprintf(Buffer, "%f ", x1);
            WRF_wstring(a_fapi_font->memory, a_output, Buffer);
        }
        WRF_wstring(a_fapi_font->memory, a_output, "] def\n");
    }
    WRF_wstring(a_fapi_font->memory, a_output, "currentdict end\ncurrentfile eexec\n");
    write_private_dictionary(a_fapi_font, a_output, Write_CharStrings);
    if (is_MM_font(a_fapi_font)) {
        write_blend_dictionary(a_fapi_font, a_output);
    }
}
Exemple #10
0
static void
file_to_fake_path(clist_file_ptr file, char fname[gp_file_name_sizeof])
{
    gs_sprintf(fname, ENC_FILE_STR, file);
}
Exemple #11
0
/*
 * Write the Private dictionary.  This is a separate procedure only for
 * readability.  write_CharString is a parameter so that we can encrypt
 * Subrs and CharStrings when the font's lenIV == -1 but we are writing
 * the font with lenIV = 0.
 */
static int
write_Private(stream *s, gs_font_type1 *pfont,
              gs_glyph *subset_glyphs, uint subset_size,
              gs_glyph notdef, int lenIV,
              int (*write_CharString)(stream *, const void *, uint),
              const param_printer_params_t *ppp)
{
    const gs_type1_data *const pdata = &pfont->data;
    printer_param_list_t rlist;
    gs_param_list *const plist = (gs_param_list *)&rlist;
    int code = s_init_param_printer(&rlist, ppp, s);
    byte *SubrsWithMM = 0;

    if (code < 0)
        return 0;
    stream_puts(s, "dup /Private 17 dict dup begin\n");
    stream_puts(s, "/-|{string currentfile exch readstring pop}executeonly def\n");
    stream_puts(s, "/|-{noaccess def}executeonly def\n");
    stream_puts(s, "/|{noaccess put}executeonly def\n");
    {
        static const gs_param_item_t private_items[] = {
            {"BlueFuzz", gs_param_type_int,
             offset_of(gs_type1_data, BlueFuzz)},
            {"BlueScale", gs_param_type_float,
             offset_of(gs_type1_data, BlueScale)},
            {"BlueShift", gs_param_type_float,
             offset_of(gs_type1_data, BlueShift)},
            {"ExpansionFactor", gs_param_type_float,
             offset_of(gs_type1_data, ExpansionFactor)},
            {"ForceBold", gs_param_type_bool,
             offset_of(gs_type1_data, ForceBold)},
            {"LanguageGroup", gs_param_type_int,
             offset_of(gs_type1_data, LanguageGroup)},
            {"RndStemUp", gs_param_type_bool,
             offset_of(gs_type1_data, RndStemUp)},
            gs_param_item_end
        };
        gs_type1_data defaults;

        defaults.BlueFuzz = 1;
        defaults.BlueScale = (float)0.039625;
        defaults.BlueShift = 7.0;
        defaults.ExpansionFactor = (float)0.06;
        defaults.ForceBold = false;
        defaults.LanguageGroup = 0;
        defaults.RndStemUp = true;
        code = gs_param_write_items(plist, pdata, &defaults, private_items);
        if (code < 0)
            return code;
        if (lenIV != 4) {
            code = param_write_int(plist, "lenIV", &lenIV);
            if (code < 0)
                return code;
        }
        write_float_array(plist, "BlueValues", pdata->BlueValues.values,
                          pdata->BlueValues.count);
        write_float_array(plist, "OtherBlues", pdata->OtherBlues.values,
                          pdata->OtherBlues.count);
        write_float_array(plist, "FamilyBlues", pdata->FamilyBlues.values,
                          pdata->FamilyBlues.count);
        write_float_array(plist, "FamilyOtherBlues", pdata->FamilyOtherBlues.values,
                          pdata->FamilyOtherBlues.count);
        write_float_array(plist, "StdHW", pdata->StdHW.values,
                          pdata->StdHW.count);
        write_float_array(plist, "StdVW", pdata->StdVW.values,
                          pdata->StdVW.count);
        write_float_array(plist, "StemSnapH", pdata->StemSnapH.values,
                          pdata->StemSnapH.count);
        write_float_array(plist, "StemSnapV", pdata->StemSnapV.values,
                          pdata->StemSnapV.count);
    }
    write_uid(s, &pfont->UID);
    stream_puts(s, "/MinFeature{16 16} def\n");
    stream_puts(s, "/password 5839 def\n");

    /*
     * Write the Subrs.  We always write them all, even for subsets.
     * (We will fix this someday.)
     */

    {
        int n, i;
        gs_glyph_data_t gdata;
        int code;

        gdata.memory = pfont->memory;
        for (n = 0;
             (code = pdata->procs.subr_data(pfont, n, false, &gdata)) !=
                 gs_error_rangecheck;
             ) {
            ++n;
            if (code >= 0)
                gs_glyph_data_free(&gdata, "write_Private(Subrs)");
        }
        if (pfont->data.WeightVector.count != 0)
            SubrsWithMM = gs_alloc_bytes(pfont->memory, n, "Subrs record");

        pprintd1(s, "/Subrs %d array\n", n);

        /* prescan the /Subrs array to see if any of the Subrs call out to OtherSubrs */
        if (pfont->data.WeightVector.count != 0) {
            for (i = 0; i < n; ++i) {
                if ((code = pdata->procs.subr_data(pfont, i, false, &gdata)) >= 0) {
                        code = CheckSubrForMM(&gdata, pfont);
                        if (code < 0) {
                            if (SubrsWithMM != 0)
                                gs_free_object(pfont->memory, SubrsWithMM, "free Subrs record");
                            return code;
                        }
                        if (SubrsWithMM != 0)
                            SubrsWithMM[i] = code;
                }
            }
        }

        for (i = 0; i < n; ++i)
            if ((code = pdata->procs.subr_data(pfont, i, false, &gdata)) >= 0) {
                char buf[50];

                if (gdata.bits.size) {
                    if (pfont->data.WeightVector.count != 0) {
                        byte *stripped;
                        int length;

                        length = strip_othersubrs(&gdata, pfont, NULL, SubrsWithMM);
                        stripped = gs_alloc_bytes(pfont->memory, length, "Subrs copy for OtherSubrs");
                        code = strip_othersubrs(&gdata, pfont, stripped, SubrsWithMM);
                        if (code < 0) {
                            if (SubrsWithMM != 0)
                                gs_free_object(pfont->memory, SubrsWithMM, "free Subrs record");
                            return code;
                        }
                        gs_sprintf(buf, "dup %d %u -| ", i, code);
                        stream_puts(s, buf);
                        write_CharString(s, stripped, code);
                        gs_free_object(pfont->memory, stripped, "free Subrs copy for OtherSubrs");
                    } else {
                        gs_sprintf(buf, "dup %d %u -| ", i, gdata.bits.size);
                        stream_puts(s, buf);
                        write_CharString(s, gdata.bits.data, gdata.bits.size);
                    }
                    stream_puts(s, " |\n");
                }
                gs_glyph_data_free(&gdata, "write_Private(Subrs)");
            }
        stream_puts(s, "|-\n");
    }

    /* We don't write OtherSubrs -- there had better not be any! */

    /* Write the CharStrings. */

    {
        int num_chars = 0;
        gs_glyph glyph;
        psf_glyph_enum_t genum;
        gs_glyph_data_t gdata;
        int code;

        gdata.memory = pfont->memory;
        psf_enumerate_glyphs_begin(&genum, (gs_font *)pfont, subset_glyphs,
                                    (subset_glyphs ? subset_size : 0),
                                    GLYPH_SPACE_NAME);
        for (glyph = gs_no_glyph;
             (code = psf_enumerate_glyphs_next(&genum, &glyph)) != 1;
             )
            if (code == 0 &&
                (code = pdata->procs.glyph_data(pfont, glyph, &gdata)) >= 0
                ) {
                ++num_chars;
                gs_glyph_data_free(&gdata, "write_Private(CharStrings)");
            }
        pprintd1(s, "2 index /CharStrings %d dict dup begin\n", num_chars);
        psf_enumerate_glyphs_reset(&genum);
        for (glyph = gs_no_glyph;
             (code = psf_enumerate_glyphs_next(&genum, &glyph)) != 1;
            )
            if (code == 0 &&
                (code = pdata->procs.glyph_data(pfont, glyph, &gdata)) >= 0
                ) {
                gs_const_string gstr;
                int code;
                byte *stripped;

                code = pfont->procs.glyph_name((gs_font *)pfont, glyph, &gstr);
                if (code < 0) {
                    if (SubrsWithMM != 0)
                        gs_free_object(pfont->memory, SubrsWithMM, "free Subrs record");
                    return code;
                }

                stream_puts(s, "/");
                stream_write(s, gstr.data, gstr.size);

                if (pfont->data.WeightVector.count != 0) {
                    gs_bytestring *data = (gs_bytestring *)&gdata.bits;

                    stripped = gs_alloc_bytes(pfont->memory, data->size, "CharStrings copy for OtherSubrs");
                    code = strip_othersubrs(&gdata, pfont, stripped, SubrsWithMM);
                    if (code < 0) {
                        if (SubrsWithMM != 0)
                            gs_free_object(pfont->memory, SubrsWithMM, "free Subrs record");
                        return code;
                    }
                    pprintd1(s, " %d -| ", code);
                    write_CharString(s, stripped, code);
                    gs_free_object(pfont->memory, stripped, "free CharStrings copy for OtherSubrs");
                } else {
                    pprintd1(s, " %d -| ", gdata.bits.size);
                    write_CharString(s, gdata.bits.data, gdata.bits.size);
                }

                stream_puts(s, " |-\n");
                gs_glyph_data_free(&gdata, "write_Private(CharStrings)");
            }
    }
    if (SubrsWithMM != 0)
        gs_free_object(pfont->memory, SubrsWithMM, "free Subrs record");

    /* Wrap up. */

    stream_puts(s, "end\nend\nreadonly put\nnoaccess put\n");
    s_release_param_printer(&rlist);
    return 0;
}
Exemple #12
0
void main(void)
{
    int code;
    int exit_code;
    int argc;
    char **argv;
    char dformat[64], ddevice[32];
    SInt32        response;

    /* Initialize operating environment */
#if TARGET_API_MAC_CARBON
    MoreMasterPointers(224);
#else
    MoreMasters();
#endif
    InitCursor();
    FlushEvents(everyEvent,0);

    if (AEInstallEventHandler(kCoreEventClass,kAEQuitApplication,
                              NewAEEventHandlerUPP((AEEventHandlerProcPtr) quitAppEventHandler),
                              0L,false) != noErr)
        ExitToShell();

        gActionFunctionScrollUPP = NewControlActionUPP(&actionFunctionScroll);

    Gestalt(gestaltMenuMgrAttr,&response);
    if(response & gestaltMenuMgrAquaLayoutMask)
                gRunningOnX = true;

    /* Initialize SIOUX */
    SIOUXSettings.initializeTB = false;
    SIOUXSettings.standalone = false;
    SIOUXSettings.asktosaveonclose = false;
    SIOUXSettings.sleep = GetCaretTime();
    SIOUXSettings.userwindowtitle = "\pGhostscript";

    /* Get arguments from user */
    argc = ccommand(&argv);

    /* Show command line window */
    if (InstallConsole(0))
        ExitToShell();

    /* Part of fudge to make SIOUX accept characters without becoming modal */
    SelectWindow(SIOUXTextWindow->window);
    PostEvent(keyDown, 0x4c00);  // Enter
    ReadCharsFromConsole(dformat, 0x7FFF);
    clrscr();

    /* Add in the display format as the first command line argument */
    if (argc >= MAX_ARGS - 1)
    {
       printf("Too many command line arguments\n");
       return;
    }

    memmove(&argv[3], &argv[1], (argc-1) * sizeof(char**));
    argc += 2;
    argv[1] = ddevice;
    argv[2] = dformat;

    gs_sprintf(ddevice, "-sDEVICE=display");
    gs_sprintf(dformat, "-dDisplayFormat=%d", display_format);

    /* Run Ghostscript */
    if (gsapi_new_instance(&instance, NULL) < 0)
    {
       printf("Can't create Ghostscript instance\n");
       return;
    }

#ifdef DEBUG
    visual_tracer_init();
    set_visual_tracer(&visual_tracer);
#endif

    gsapi_set_stdio(instance, gsdll_stdin, gsdll_stdout, gsdll_stderr);
    gsapi_set_poll(instance, gsdll_poll);
    gsapi_set_display_callback(instance, &display);

    code = gsapi_init_with_args(instance, argc, argv);
    if (code == 0)
       code = gsapi_run_string(instance, start_string, 0, &exit_code);
    else
    {
       printf("Failed to initialize. Error %d.\n", code);
       fflush(stdout);
    }
    code = gsapi_exit(instance);
    if (code != 0)
    {
       printf("Failed to terminate. Error %d.\n", code);
       fflush(stdout);
    }

    gsapi_delete_instance(instance);

#ifdef DEBUG
    visual_tracer_close();
#endif

    /* Ghostscript has finished - let user see output before quitting */
    WriteCharsToConsole("\r[Finished - hit any key to quit]", 33);
    fflush(stdout);

    /* Process events until a key is hit or user quits from menu */
    while(!gDone)
    {
        EventRecord eventStructure;

        if(WaitNextEvent(everyEvent,&eventStructure,SIOUXSettings.sleep,NULL))
        {
            if (eventStructure.what == keyDown)
            gDone = true;

            doEvents(&eventStructure);
        }
        else
            SIOUXHandleOneEvent(&eventStructure);
    }
}