Esempio n. 1
0
  ft_outline_glyph_init( FT_Glyph      outline_glyph,
                         FT_GlyphSlot  slot )
  {
    FT_OutlineGlyph  glyph   = (FT_OutlineGlyph)outline_glyph;
    FT_Error         error   = FT_Err_Ok;
    FT_Library       library = FT_GLYPH( glyph )->library;
    FT_Outline*      source  = &slot->outline;
    FT_Outline*      target  = &glyph->outline;


    /* check format in glyph slot */
    if ( slot->format != FT_GLYPH_FORMAT_OUTLINE )
    {
      error = FT_Err_Invalid_Glyph_Format;
      goto Exit;
    }

    /* allocate new outline */
    error = FT_Outline_New( library, source->n_points, source->n_contours,
                            &glyph->outline );
    if ( error )
      goto Exit;

    FT_Outline_Copy( source, target );

  Exit:
    return error;
  }
Esempio n. 2
0
PyObject *
Py_Outline_cnew(FT_Outline *outline)
{
    Py_Outline *self;

    self = (Py_Outline *)(&Py_Outline_Type)->tp_alloc(&Py_Outline_Type, 0);
    if (self == NULL) {
        return NULL;
    }

    self->points = NULL;
    self->codes = NULL;
    self->inited = 0;

    if (ftpy_exc(
            FT_Outline_New(get_ft_library(),
                           outline->n_points,
                           outline->n_contours,
                           &self->x))) {
        Py_DECREF(self);
        return NULL;
    }

    self->inited = 1;

    if (ftpy_exc(
            FT_Outline_Copy(outline, &self->x))) {
        Py_DECREF(self);
        return NULL;
    }

    self->base.owner = NULL;
    return (PyObject *)self;
}
Esempio n. 3
0
  static
  FT_Error  ft_outline_glyph_copy( FT_OutlineGlyph  source,
                                   FT_OutlineGlyph  target )
  {
    FT_Error    error;
    FT_Library  library = FT_GLYPH( source )->library;


    error = FT_Outline_New( library, source->outline.n_points,
                            source->outline.n_contours, &target->outline );
    if ( !error )
      FT_Outline_Copy( &source->outline, &target->outline );

    return error;
  }
Esempio n. 4
0
/*
 * \brief Get and prepare a FreeType glyph
 */
static void drawing_make_glyph(ASS_Drawing *drawing, void *fontconfig_priv,
                               ASS_Font *font)
{
    FT_OutlineGlyph glyph;

    // This is hacky...
    glyph = (FT_OutlineGlyph) ass_font_get_glyph(fontconfig_priv, font,
                                                 (uint32_t) ' ', 0, 0);
    if (glyph) {
        FT_Outline_Done(drawing->ftlibrary, &glyph->outline);
        FT_Outline_New(drawing->ftlibrary, GLYPH_INITIAL_POINTS,
                       GLYPH_INITIAL_CONTOURS, &glyph->outline);

        glyph->outline.n_contours = 0;
        glyph->outline.n_points = 0;
        glyph->root.advance.x = glyph->root.advance.y = 0;
    }
    drawing->glyph = glyph;
}
Esempio n. 5
0
static
FT_Error  ft_outline_glyph_init(FT_OutlineGlyph glyph,
                                FT_GlyphSlot slot)
{
	FT_Error error   = FT_Err_Ok;
	FT_Library library = FT_GLYPH(glyph)->library;
	FT_Outline  *source  = &slot->outline;
	FT_Outline  *target  = &glyph->outline;


	/* check format in glyph slot */
	if(slot->format != ft_glyph_format_outline)
	{
		error = FT_Err_Invalid_Glyph_Format;
		goto Exit;
	}

	/* allocate new outline */
	error = FT_Outline_New(library, source->n_points, source->n_contours,
	                       &glyph->outline);

	if(error)
	{
		goto Exit;
	}

	/* copy it */
	MEM_Copy(target->points, source->points,
	         source->n_points * sizeof(FT_Vector));

	MEM_Copy(target->tags, source->tags,
	         source->n_points * sizeof(FT_Byte));

	MEM_Copy(target->contours, source->contours,
	         source->n_contours * sizeof(FT_Short));

	/* copy all flags, except the `ft_outline_owner' one */
	target->flags = source->flags | ft_outline_owner;

Exit:
	return error;
}
Esempio n. 6
0
/*
 * \brief Create and initialize a new drawing and return it
 */
ASS_Drawing *ass_drawing_new(ASS_Library *lib, FT_Library ftlib)
{
    ASS_Drawing *drawing;

    drawing = calloc(1, sizeof(*drawing));
    drawing->text = calloc(1, DRAWING_INITIAL_SIZE);
    drawing->size = DRAWING_INITIAL_SIZE;
    drawing->cbox.xMin = drawing->cbox.yMin = INT_MAX;
    drawing->cbox.xMax = drawing->cbox.yMax = INT_MIN;
    drawing->ftlibrary = ftlib;
    drawing->library   = lib;
    drawing->scale_x = 1.;
    drawing->scale_y = 1.;
    drawing->max_contours = GLYPH_INITIAL_CONTOURS;
    drawing->max_points = GLYPH_INITIAL_POINTS;

    FT_Outline_New(drawing->ftlibrary, GLYPH_INITIAL_POINTS,
            GLYPH_INITIAL_CONTOURS, &drawing->outline);
    drawing->outline.n_contours = 0;
    drawing->outline.n_points = 0;

    return drawing;
}
Esempio n. 7
0
  ft_outline_glyph_init( FT_Glyph      outline_glyph,
                         FT_GlyphSlot  slot )
  {
    FT_OutlineGlyph  glyph   = (FT_OutlineGlyph)outline_glyph;
    FT_Error         error   = FT_Err_Ok;
    FT_Library       library = FT_GLYPH( glyph )->library;
    FT_Outline*      source  = &slot->outline;
    FT_Outline*      target  = &glyph->outline;


    /* check format in glyph slot */
    if ( slot->format != FT_GLYPH_FORMAT_OUTLINE )
    {
      error = FT_Err_Invalid_Glyph_Format;
      goto Exit;
    }

    /* allocate new outline */
    error = FT_Outline_New( library, source->n_points, source->n_contours,
                            &glyph->outline );
    if ( error )
      goto Exit;

    /* copy it */
    FT_ARRAY_COPY( target->points, source->points, source->n_points );

    FT_ARRAY_COPY( target->tags, source->tags, source->n_points );

    FT_ARRAY_COPY( target->contours, source->contours, source->n_contours );

    /* copy all flags, except the `FT_OUTLINE_OWNER' one */
    target->flags = source->flags | FT_OUTLINE_OWNER;

  Exit:
    return error;
  }
Esempio n. 8
0
FT_Error ft_OutlineStroke( FT_Library   library,
                           FT_Outline  *Outline,
                           int          Thickness )
{
  FT_Error   err = 0;
  FT_Outline OutlineReversed;
  FT_Outline OutlineFattened;
  FT_Outline OutlineStroke;

  if ( Outline == NULL ) {
     goto failure;
  }

  err = FT_Outline_New( library,
                        Outline->n_points,
                        Outline->n_contours,
                        &OutlineReversed );
  if ( err != 0 ) {
     goto failure;
  }

  err = FT_Outline_New( library,
                        Outline->n_points,
                        Outline->n_contours,
                        &OutlineFattened );
  if ( err != 0 ) {
     goto failure;
  }

  err = FT_Outline_Copy( Outline, &OutlineReversed );
  if ( err != 0 ) {
     goto failure;
  }

  err = FT_Outline_Copy( Outline, &OutlineFattened );
  if ( err != 0 ) {
     goto failure;
  }

  err = FT_Outline_New( library,
                        Outline->n_points   * 2,
                        Outline->n_contours * 2,
                        &OutlineStroke );
  if ( err != 0 ) {
     goto failure;
  }

  /* Perform fattening operation */
  err = FT_Outline_Embolden( &OutlineFattened, Thickness << 1 );
  if ( err != 0 ) {
     goto failure;
  }

  /* Perform reversal operation */
  ft_OutlineReverse( Outline,
                     &OutlineReversed );

  FT_Outline_Translate( &OutlineReversed, Thickness, Thickness );

  /* Merge outlines */
  ft_OutlineMerge( &OutlineFattened,
                   &OutlineReversed,
                   &OutlineStroke );

  /* delete temporary and input outline */
  err = FT_Outline_Done( library, &OutlineReversed );
  if ( err != 0 ) {
     goto failure;
  }

  err = FT_Outline_Done( library, &OutlineFattened );
  if ( err != 0 ) {
     goto failure;
  }

  err = FT_Outline_Done( library, Outline );
  if ( err != 0 ) {
     goto failure;
  }

  /* finally copy the outline - its not clear from ft docs if this
     does the right thing but i _think_ its correct */
  memcpy( Outline, &OutlineStroke, sizeof( FT_Outline ) );

  return 0;

failure:

   return err;
}