Ejemplo n.º 1
0
  FT_EXPORT_DEF( FT_Error )  FT_Outline_Copy( FT_Outline*  source,
                                              FT_Outline  *target )
  {
    FT_Int  is_owner;


    if ( !source            || !target            ||
         source->n_points   != target->n_points   ||
         source->n_contours != target->n_contours )
      return FT_Err_Invalid_Argument;

    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 */
    is_owner      = target->flags & ft_outline_owner;
    target->flags = source->flags;

    target->flags &= ~ft_outline_owner;
    target->flags |= is_owner;

    return FT_Err_Ok;
  }
Ejemplo n.º 2
0
  EXPORT_FUNC
  TT_Error  TT_Check_And_Access_Frame( STREAM_ARGS FRAME_ARGS Long  size )
  {
    TT_Error  error;
    Long      readBytes;


    if ( CUR_Frame.address != NULL )
      return TT_Err_Nested_Frame_Access;

    readBytes = CUR_Stream->map->size - CUR_Stream->pos;
    if ( size > readBytes )
    {
      /* There is overflow, we allocate a new block then */
      if ( ALLOC( CUR_Frame.address, size ) )
        return error;

      CUR_Frame.size = size;

      /* copy the valid part */
      MEM_Copy( CUR_Frame.address, 
                MAP_Address( CUR_Stream->map ) + CUR_Stream->pos,
                readBytes );
    }
    else
    {
      CUR_Frame.size    = size;
      CUR_Frame.address = MAP_Address( CUR_Stream->map ) + CUR_Stream->pos;
    }

    CUR_Frame.cursor = CUR_Frame.address;
    return TT_Err_Ok;
  }
Ejemplo n.º 3
0
  static
  FT_Error  get_t1_glyph_name( T1_Face     face,
                               FT_UInt     glyph_index,
                               FT_Pointer  buffer,
                               FT_UInt     buffer_max )
  {
    FT_String*  gname;


    gname = face->type1.glyph_names[glyph_index];

    if ( buffer_max > 0 )
    {
      FT_UInt  len = strlen( gname );


      if (len >= buffer_max)
        len = buffer_max - 1;

      MEM_Copy( buffer, gname, len );
      ((FT_Byte*)buffer)[len] = 0;
    }

    return T1_Err_Ok;
  }
Ejemplo n.º 4
0
static
FT_Error  ft_bitmap_copy(FT_Memory memory,
                         FT_Bitmap  *source,
                         FT_Bitmap  *target)
{
	FT_Error error;
	FT_Int pitch = source->pitch;
	FT_ULong size;


	*target = *source;

	if(pitch < 0)
	{
		pitch = -pitch;
	}

	size = (FT_ULong)(pitch * source->rows);

	if(!ALLOC(target->buffer, size))
	{
		MEM_Copy(source->buffer, target->buffer, size);
	}

	return error;
}
Ejemplo 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;
}
Ejemplo n.º 6
0
  EXPORT_FUNC
  TT_Error  TT_Read_File( STREAM_ARGS void*  buffer, Long  count )
  {
    if ( CUR_Stream->pos + count > CUR_Stream->map->size )
      return TT_Err_Invalid_File_Read;

    MEM_Copy( buffer,
              MAP_Address( CUR_Stream->map ) + CUR_Stream->pos, count );
    CUR_Stream->pos += count;

    return TT_Err_Ok;
  }
Ejemplo n.º 7
0
  /* read a glyph name and return the equivalent glyph index */
  static
  FT_UInt  afm_atoindex( FT_Byte**  start,
                         FT_Byte*   limit,
                         T1_Font*   type1 )
  {
    FT_Byte*  p = *start;
    FT_Int    len;
    FT_UInt   result = 0;
    char      temp[64];


    /* skip whitespace */
    while ( ( *p == ' ' || *p == '\t' || *p == ':' || *p == ';' ) &&
            p < limit                                             )
      p++;
    *start = p;

    /* now, read glyph name */
    while ( IS_ALPHANUM( *p ) && p < limit )
      p++;

    len = p - *start;

    if ( len > 0 && len < 64 )
    {
      FT_Int  n;


      /* copy glyph name to intermediate array */
      MEM_Copy( temp, *start, len );
      temp[len] = 0;

      /* lookup glyph name in face array */
      for ( n = 0; n < type1->num_glyphs; n++ )
      {
        char*  gname = (char*)type1->glyph_names[n];


        if ( gname && gname[0] == temp[0] && strcmp( gname, temp ) == 0 )
        {
          result = n;
          break;
        }
      }
    }
    *start = p;
    return result;
  }
Ejemplo n.º 8
0
BASE_FUNC(FT_Error)  FT_Read_Stream_At(FT_Stream stream,
                                       FT_ULong pos,
                                       FT_Byte    *buffer,
                                       FT_ULong count)
{
    FT_Error error = FT_Err_Ok;
    FT_ULong read_bytes;


    if(pos >= stream->size)
    {
        FT_ERROR(("FT_Read_Stream_At:"));
        FT_ERROR((" invalid i/o; pos = 0x%lx, size = 0x%lx\n",
                  pos, stream->size));

        return FT_Err_Invalid_Stream_Operation;
    }

    if(stream->read)
    {
        read_bytes = stream->read(stream, pos, buffer, count);
    }
    else
    {
        read_bytes = stream->size - pos;

        if(read_bytes > count)
        {
            read_bytes = count;
        }

        MEM_Copy(buffer, stream->base + pos, read_bytes);
    }

    stream->pos = pos + read_bytes;

    if(read_bytes < count)
    {
        FT_ERROR(("FT_Read_Stream_At:"));
        FT_ERROR((" invalid read; expected %lu bytes, got %lu\n",
                  count, read_bytes));

        error = FT_Err_Invalid_Stream_Operation;
    }

    return error;
}
Ejemplo n.º 9
0
BASE_FUNC(FT_Error) FT_Read_Fields(FT_Stream stream,
                                   const FT_Frame_Field   *fields,
                                   void                  *structure)
{
    FT_Error error;
    FT_Bool frame_accessed = 0;


    if(!fields || !stream)
    {
        return FT_Err_Invalid_Argument;
    }

    error = FT_Err_Ok;

    do
    {
        FT_ULong value;
        FT_Int sign_shift;
        FT_Byte  *p;


        switch(fields->value)
        {
        case ft_frame_start: /* access a new frame */
            error = FT_Access_Frame(stream, fields->offset);

            if(error)
            {
                goto Exit;
            }

            frame_accessed = 1;
            fields++;
            continue; /* loop! */

        case ft_frame_bytes: /* read a byte sequence */
        case ft_frame_skip: /* skip some bytes      */
        {
            FT_Int len = fields->size;


            if(stream->cursor + len > stream->limit)
            {
                error = FT_Err_Invalid_Stream_Operation;
                goto Exit;
            }

            if(fields->value == ft_frame_bytes)
            {
                p = (FT_Byte *)structure + fields->offset;
                MEM_Copy(p, stream->cursor, len);
            }

            stream->cursor += len;
            fields++;
            continue;
        }

        case ft_frame_byte:
        case ft_frame_schar: /* read a single byte */
            value = GET_Byte();
            sign_shift = 24;
            break;

        case ft_frame_short_be:
        case ft_frame_ushort_be: /* read a 2-byte big-endian short */
            value = GET_UShort();
            sign_shift = 16;
            break;

        case ft_frame_short_le:
        case ft_frame_ushort_le: /* read a 2-byte little-endian short */
        {
            FT_Byte  *p;


            value = 0;
            p     = stream->cursor;

            if(p + 1 < stream->limit)
            {
                value = (FT_UShort)p[0] | ((FT_UShort)p[1] << 8);
                stream->cursor += 2;
            }

            sign_shift = 16;
            break;
        }

        case ft_frame_long_be:
        case ft_frame_ulong_be: /* read a 4-byte big-endian long */
            value = GET_ULong();
            sign_shift = 0;
            break;

        case ft_frame_long_le:
        case ft_frame_ulong_le: /* read a 4-byte little-endian long */
        {
            FT_Byte  *p;


            value = 0;
            p     = stream->cursor;

            if(p + 3 < stream->limit)
            {
                value = (FT_ULong)p[0]         |
                        ((FT_ULong)p[1] << 8) |
                        ((FT_ULong)p[2] << 16) |
                        ((FT_ULong)p[3] << 24);
                stream->cursor += 4;
            }

            sign_shift = 0;
            break;
        }

        case ft_frame_off3_be:
        case ft_frame_uoff3_be: /* read a 3-byte big-endian long */
            value = GET_UOffset();
            sign_shift = 8;
            break;

        case ft_frame_off3_le:
        case ft_frame_uoff3_le: /* read a 3-byte little-endian long */
        {
            FT_Byte  *p;


            value = 0;
            p     = stream->cursor;

            if(p + 2 < stream->limit)
            {
                value = (FT_ULong)p[0]         |
                        ((FT_ULong)p[1] << 8) |
                        ((FT_ULong)p[2] << 16);
                stream->cursor += 3;
            }

            sign_shift = 8;
            break;
        }

        default:
            /* otherwise, exit the loop */
            goto Exit;
        }

        /* now, compute the signed value is necessary */
        if(fields->value & FT_FRAME_OP_SIGNED)
        {
            value = (FT_ULong)((FT_Int32)(value << sign_shift) >> sign_shift);
        }

        /* finally, store the value in the object */

        p = (FT_Byte *)structure + fields->offset;

        switch(fields->size)
        {
        case 1:
            *(FT_Byte *)p = (FT_Byte)value;
            break;

        case 2:
            *(FT_UShort *)p = (FT_UShort)value;
            break;

        case 4:
            *(FT_UInt32 *)p = (FT_UInt32)value;
            break;

        default: /* for 64-bit systems */
            *(FT_ULong *)p = (FT_ULong)value;
        }

        /* go to next field */
        fields++;
    }
Ejemplo n.º 10
0
static
FT_String  *Get_Name(TT_Face face,
                     FT_UShort nameid)
{
	FT_Memory memory = face->root.memory;
	FT_UShort n;
	TT_NameRec  *rec;
	FT_Bool wide_chars = 1;


	rec = face->name_table.names;

	for(n = 0; n < face->name_table.numNameRecords; n++, rec++)
	{
		if(rec->nameID == nameid)
		{
			/* found the name -- now create an ASCII string from it */
			FT_Bool found = 0;


			/* test for Microsoft English language */
			if(rec->platformID == TT_PLATFORM_MICROSOFT &&
			        rec->encodingID <= TT_MS_ID_UNICODE_CS   &&
			        (rec->languageID & 0x3FF) == 0x009)
			{
				found = 1;
			}
			/* test for Apple Unicode encoding */
			else if(rec->platformID == TT_PLATFORM_APPLE_UNICODE)
			{
				found = 1;
			}
			/* test for Apple Roman */
			else if(rec->platformID == TT_PLATFORM_MACINTOSH &&
			        rec->languageID == TT_MAC_ID_ROMAN)
			{
				found      = 1;
				wide_chars = 0;
			}

			/* found a Unicode name */
			if(found)
			{
				FT_String  *string;
				FT_UInt len;


				if(wide_chars)
				{
					FT_UInt m;


					len = (FT_UInt)rec->stringLength / 2;

					if(MEM_Alloc(string, len + 1))
					{
						return NULL;
					}

					for(m = 0; m < len; m++)
						string[m] = rec->string[2 * m + 1];
				}
				else
				{
					len = rec->stringLength;

					if(MEM_Alloc(string, len + 1))
					{
						return NULL;
					}

					MEM_Copy(string, rec->string, len);
				}

				string[len] = '\0';
				return string;
			}
		}
	}

	return NULL;
}