Exemplo n.º 1
0
int ttfFont__Open_aux(ttfFont *self, ttfInterpreter *tti, gx_ttfReader *r, gs_font_type42 *pfont,
               const gs_matrix * char_tm, const gs_log2_scale_point *log2_scale,
               bool design_grid)
{
    gs_point char_size, subpix_origin;
    gs_matrix post_transform;
    /*
     * Ghostscript proceses a TTC index in gs/lib/gs_ttf.ps,
     * and *pfont already adjusted to it.
     * Therefore TTC headers never comes here.
     */
    unsigned int nTTC = 0;
    bool dg;

    decompose_matrix(pfont, char_tm, log2_scale, design_grid, &char_size, &subpix_origin, &post_transform, &dg);
    switch(ttfFont__Open(tti, self, &r->super, nTTC, char_size.x, char_size.y, dg)) {
        case fNoError:
            return 0;
        case fMemoryError:
            return_error(gs_error_VMerror);
        case fUnimplemented:
            return_error(gs_error_unregistered);
        case fBadInstruction:
            WarnBadInstruction(pfont, -1);
            goto recover;
        case fPatented:
            WarnPatented(pfont, self, "The font");
        recover:
            self->patented = true;
            return 0;
        default:
            {	int code = r->super.Error(&r->super);

                if (code < 0)
                    return code;
                return_error(gs_error_invalidfont);
            }
    }
}
Exemplo n.º 2
0
int gx_ttf_outline(ttfFont *ttf, gx_ttfReader *r, gs_font_type42 *pfont, int glyph_index,
        const gs_matrix *m, const gs_log2_scale_point *pscale,
        gx_path *path, bool design_grid)
{
    gx_ttfExport e;
    ttfOutliner o;
    gs_point char_size, subpix_origin;
    gs_matrix post_transform;
    /* Ghostscript proceses a TTC index in gs/lib/gs_ttf.ps, */
    /* so that TTC never comes here. */
    FloatMatrix m1;
    bool dg;
    uint gftt = gs_currentgridfittt(pfont->dir);
    bool ttin = (gftt & 1);
    /*	gs_currentgridfittt values (binary) :
        00 - no grid fitting;
        01 - Grid fit with TT interpreter; On failure warn and render unhinted.
        10 - Interpret in the design grid and then autohint.
        11 - Grid fit with TT interpreter; On failure render autohinted.
    */
    bool auth = (gftt & 2);

    decompose_matrix(pfont, m, pscale, design_grid, &char_size, &subpix_origin, &post_transform, &dg);
    m1.a = post_transform.xx;
    m1.b = post_transform.xy;
    m1.c = post_transform.yx;
    m1.d = post_transform.yy;
    m1.tx = post_transform.tx;
    m1.ty = post_transform.ty;
    e.super.bPoints = false;
    e.super.bOutline = true;
    e.super.MoveTo = gx_ttfExport__MoveTo;
    e.super.LineTo = gx_ttfExport__LineTo;
    e.super.CurveTo = gx_ttfExport__CurveTo;
    e.super.Close = gx_ttfExport__Close;
    e.super.Point = gx_ttfExport__Point;
    e.super.SetWidth = gx_ttfExport__SetWidth;
    e.super.DebugPaint = gx_ttfExport__DebugPaint;
    e.error = 0;
    e.path = path;
    e.w.x = 0;
    e.w.y = 0;
    e.monotonize = auth;
    gx_ttfReader__Reset(r);
    ttfOutliner__init(&o, ttf, &r->super, &e.super, true, false, pfont->WMode != 0);
    switch(ttfOutliner__Outline(&o, glyph_index, subpix_origin.x, subpix_origin.y, &m1)) {
        case fBadInstruction:
            WarnBadInstruction(pfont, glyph_index);
            goto recover;
        case fPatented:
            /* The returned outline did not apply a bytecode (it is not grid-fitted). */
            if (!auth)
                WarnPatented(pfont, ttf, "Some glyphs of the font");
        recover :
            if (!design_grid && auth)
                return grid_fit(pfont->dir->san, path, pfont, pscale, &e, &o);
            /* Falls through. */
        case fNoError:
            if (!design_grid && !ttin && auth)
                return grid_fit(pfont->dir->san, path, pfont, pscale, &e, &o);
            ttfOutliner__DrawGlyphOutline(&o);
            if (e.error)
                return e.error;
            return 0;
        case fMemoryError:
            return_error(gs_error_VMerror);
        case fUnimplemented:
            return_error(gs_error_unregistered);
        default:
            {	int code = r->super.Error(&r->super);

                if (code < 0)
                    return code;
                return_error(gs_error_invalidfont);
            }
    }
}
Exemplo n.º 3
0
Arquivo: parallel.c Projeto: gz/cslab
/** 
 * Main driver code for the parallel lab. Generates the matrix of the
 * specified size, initiates the decomposition and checking
 * routines. 
 */
int main (int argc, char *argv[]) 
{
  int size = 0;
  double *a = NULL;
  double *lu = NULL;
 
  clock_t start, time1, time2; 
  struct timeval start_timeval, end_timeval;
  double elapsed_secs, elapsed_total_secs, cpu_secs;

  /* Bail out if we don't have the correct number of parameters */
  if (argc!=2) {
    printf("This program is used to decompose a (random) matrix A into its components L and U.\n");
    printf("Usage: %s <matrix size>\n", argv[0]);
    return -1;
  }
  size = atoi(argv[1]);

  /* Adjust matrix size */
  if (size < MIN_MATRIX_SIZE) {
    printf("Setting matrix size to minimum value %d.\n", MIN_MATRIX_SIZE);
    size = MIN_MATRIX_SIZE;
  } else if (size > MAX_MATRIX_SIZE) {
    printf("Setting matrix size to maximum value %d.\n", MAX_MATRIX_SIZE);
    size = MAX_MATRIX_SIZE;
  }
  
  /* Generate data. */
  printf("LU matrix decomposition, starting warmup...\n");
  printf(" - Generating a %i * %i matrix\n", size, size);
  a = (double*)malloc(sizeof(double)*size*size);
  lu = (double*)malloc(sizeof(double)*size*size);
  if (a==NULL || lu==NULL) {
    printf("Not enough memory!\n");
    return -1;
  }
  fill_matrix(a, size);
  print_matrix(a, size);
  memcpy(lu, a, sizeof(double)*size*size);

  /* Start LU decomposition. */
  printf("Decomposing the matrix into its components...\n");
  gettimeofday(&start_timeval, NULL);
  start = clock();
  decompose_matrix(lu, size);
  time1 = clock()-start;
  gettimeofday(&end_timeval, NULL);
  elapsed_total_secs = elapsed_secs = (double)timediff_ms(&start_timeval, &end_timeval)/1000.0;
  cpu_secs = (double)(time1)/CLOCKS_PER_SEC;

  /* Verify resulting decomposition. */
  printf("Checking result...\n");
  print_matrix(lu, size);
  gettimeofday(&start_timeval, NULL);
  start = clock();
  if (check_matrix(lu, a, size))
    printf("The computation seems correct\n");
  else
    printf("The computation seems not correct\n");
  time2 = clock()-start;
  gettimeofday(&end_timeval, NULL);
  
  /* Output stats. */
  printf("\nDecomposition time: %.2fs CPU, %.2fs elapsed, %.1f%% speedup\n", 
	 cpu_secs, elapsed_secs, cpu_secs/elapsed_secs*100.0);
  elapsed_secs = (double)timediff_ms(&start_timeval, &end_timeval)/1000.0;
  elapsed_total_secs += elapsed_secs;
  cpu_secs = (double)(time2)/CLOCKS_PER_SEC;
  printf("Checking time:      %.2fs CPU, %.2fs elapsed, %.1f%% speedup\n", 
	 cpu_secs, elapsed_secs, cpu_secs/elapsed_secs*100.0);
  cpu_secs = (double)(time1+time2)/CLOCKS_PER_SEC;
  printf("Overall time:       %.2fs CPU, %.2fs elapsed, %.1f%% speedup\n", 
	 cpu_secs, elapsed_total_secs, cpu_secs/elapsed_total_secs*100.0);

  /* Free resources. */
  free(lu);
  free(a);
  return 0;
}