ReactOS  0.4.15-dev-3303-g1ade494
pfrsbit.h File Reference
#include "pfrobjs.h"
Include dependency graph for pfrsbit.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

FT_BEGIN_HEADER pfr_slot_load_bitmap (PFR_Slot glyph, PFR_Size size, FT_UInt glyph_index, FT_Bool metrics_only)
 

Function Documentation

◆ pfr_slot_load_bitmap()

FT_BEGIN_HEADER pfr_slot_load_bitmap ( PFR_Slot  glyph,
PFR_Size  size,
FT_UInt  glyph_index,
FT_Bool  metrics_only 
)

Definition at line 579 of file pfrsbit.c.

583  {
584  FT_Error error;
585  PFR_Face face = (PFR_Face) glyph->root.face;
586  FT_Stream stream = face->root.stream;
587  PFR_PhyFont phys = &face->phy_font;
588  FT_ULong gps_offset;
589  FT_ULong gps_size;
590  PFR_Char character;
591  PFR_Strike strike;
592 
593 
594  character = &phys->chars[glyph_index];
595 
596  /* look up a bitmap strike corresponding to the current */
597  /* character dimensions */
598  {
599  FT_UInt n;
600 
601 
602  strike = phys->strikes;
603  for ( n = 0; n < phys->num_strikes; n++ )
604  {
605  if ( strike->x_ppm == (FT_UInt)size->root.metrics.x_ppem &&
606  strike->y_ppm == (FT_UInt)size->root.metrics.y_ppem )
607  goto Found_Strike;
608 
609  strike++;
610  }
611 
612  /* couldn't find it */
613  return FT_THROW( Invalid_Argument );
614  }
615 
616  Found_Strike:
617 
618  /* now look up the glyph's position within the file */
619  {
620  FT_UInt char_len;
621 
622 
623  char_len = 4;
624  if ( strike->flags & PFR_BITMAP_2BYTE_CHARCODE )
625  char_len += 1;
626  if ( strike->flags & PFR_BITMAP_2BYTE_SIZE )
627  char_len += 1;
628  if ( strike->flags & PFR_BITMAP_3BYTE_OFFSET )
629  char_len += 1;
630 
631  /* access data directly in the frame to speed lookups */
632  if ( FT_STREAM_SEEK( phys->bct_offset + strike->bct_offset ) ||
633  FT_FRAME_ENTER( char_len * strike->num_bitmaps ) )
634  goto Exit;
635 
637  stream->limit,
638  strike->num_bitmaps,
639  &strike->flags,
640  character->char_code,
641  &gps_offset,
642  &gps_size );
643 
644  FT_FRAME_EXIT();
645 
646  if ( gps_size == 0 )
647  {
648  /* could not find a bitmap program string for this glyph */
649  error = FT_THROW( Invalid_Argument );
650  goto Exit;
651  }
652  }
653 
654  /* get the bitmap metrics */
655  {
656  FT_Long xpos = 0, ypos = 0, advance = 0;
657  FT_UInt xsize = 0, ysize = 0, format = 0;
658  FT_Byte* p;
659 
660 
661  /* compute linear advance */
662  advance = character->advance;
663  if ( phys->metrics_resolution != phys->outline_resolution )
665  (FT_Long)phys->outline_resolution,
666  (FT_Long)phys->metrics_resolution );
667 
668  glyph->root.linearHoriAdvance = advance;
669 
670  /* compute default advance, i.e., scaled advance; this can be */
671  /* overridden in the bitmap header of certain glyphs */
672  advance = FT_MulDiv( (FT_Fixed)size->root.metrics.x_ppem << 8,
673  character->advance,
674  (FT_Long)phys->metrics_resolution );
675 
676  if ( FT_STREAM_SEEK( face->header.gps_section_offset + gps_offset ) ||
677  FT_FRAME_ENTER( gps_size ) )
678  goto Exit;
679 
680  p = stream->cursor;
682  advance,
683  &xpos, &ypos,
684  &xsize, &ysize,
685  &advance, &format );
686  if ( error )
687  goto Exit1;
688 
689  /*
690  * Before allocating the target bitmap, we check whether the given
691  * bitmap dimensions are valid, depending on the image format.
692  *
693  * Format 0: We have a stream of pixels (with 8 pixels per byte).
694  *
695  * (xsize * ysize + 7) / 8 <= gps_size
696  *
697  * Format 1: Run-length encoding; the high nibble holds the number of
698  * white bits, the low nibble the number of black bits. In
699  * other words, a single byte can represent at most 15
700  * pixels.
701  *
702  * xsize * ysize <= 15 * gps_size
703  *
704  * Format 2: Run-length encoding; the high byte holds the number of
705  * white bits, the low byte the number of black bits. In
706  * other words, two bytes can represent at most 255 pixels.
707  *
708  * xsize * ysize <= 255 * (gps_size + 1) / 2
709  */
710  switch ( format )
711  {
712  case 0:
713  if ( ( (FT_ULong)xsize * ysize + 7 ) / 8 > gps_size )
714  error = FT_THROW( Invalid_Table );
715  break;
716  case 1:
717  if ( (FT_ULong)xsize * ysize > 15 * gps_size )
718  error = FT_THROW( Invalid_Table );
719  break;
720  case 2:
721  if ( (FT_ULong)xsize * ysize > 255 * ( ( gps_size + 1 ) / 2 ) )
722  error = FT_THROW( Invalid_Table );
723  break;
724  default:
725  FT_ERROR(( "pfr_slot_load_bitmap: invalid image type\n" ));
726  error = FT_THROW( Invalid_Table );
727  }
728 
729  if ( error )
730  {
731  if ( FT_ERR_EQ( error, Invalid_Table ) )
732  FT_ERROR(( "pfr_slot_load_bitmap: invalid bitmap dimensions\n" ));
733  goto Exit1;
734  }
735 
736  /*
737  * XXX: on 16bit systems we return an error for huge bitmaps
738  * that cause size truncation, because truncated
739  * size properties make bitmap glyphs broken.
740  */
741  if ( xpos > FT_INT_MAX ||
742  xpos < FT_INT_MIN ||
743  ysize > FT_INT_MAX ||
744  ypos > FT_INT_MAX - (FT_Long)ysize ||
745  ypos + (FT_Long)ysize < FT_INT_MIN )
746  {
747  FT_TRACE1(( "pfr_slot_load_bitmap:" ));
748  FT_TRACE1(( "huge bitmap glyph %dx%d over FT_GlyphSlot\n",
749  xpos, ypos ));
750  error = FT_THROW( Invalid_Pixel_Size );
751  }
752 
753  if ( !error )
754  {
755  glyph->root.format = FT_GLYPH_FORMAT_BITMAP;
756 
757  /* Set up glyph bitmap and metrics */
758 
759  /* XXX: needs casts to fit FT_Bitmap.{width|rows|pitch} */
760  glyph->root.bitmap.width = xsize;
761  glyph->root.bitmap.rows = ysize;
762  glyph->root.bitmap.pitch = (FT_Int)( xsize + 7 ) >> 3;
764 
765  /* XXX: needs casts to fit FT_Glyph_Metrics.{width|height} */
766  glyph->root.metrics.width = (FT_Pos)xsize << 6;
767  glyph->root.metrics.height = (FT_Pos)ysize << 6;
768  glyph->root.metrics.horiBearingX = xpos * 64;
769  glyph->root.metrics.horiBearingY = ypos * 64;
770  glyph->root.metrics.horiAdvance = FT_PIX_ROUND( ( advance >> 2 ) );
771  glyph->root.metrics.vertBearingX = - glyph->root.metrics.width >> 1;
772  glyph->root.metrics.vertBearingY = 0;
773  glyph->root.metrics.vertAdvance = size->root.metrics.height;
774 
775  /* XXX: needs casts fit FT_GlyphSlotRec.bitmap_{left|top} */
776  glyph->root.bitmap_left = (FT_Int)xpos;
777  glyph->root.bitmap_top = (FT_Int)( ypos + (FT_Long)ysize );
778 
779  if ( metrics_only )
780  goto Exit1;
781 
782  /* Allocate and read bitmap data */
783  {
784  FT_ULong len = (FT_ULong)glyph->root.bitmap.pitch * ysize;
785 
786 
787  error = ft_glyphslot_alloc_bitmap( &glyph->root, len );
788  if ( !error )
790  p,
791  stream->limit,
792  format,
793  FT_BOOL( face->header.color_flags &
795  &glyph->root.bitmap );
796  }
797  }
798 
799  Exit1:
800  FT_FRAME_EXIT();
801  }
802 
803  Exit:
804  return error;
805  }
int FT_Error
Definition: fttypes.h:300
signed long FT_Long
Definition: fttypes.h:242
unsigned long FT_ULong
Definition: fttypes.h:253
FT_BEGIN_HEADER typedef signed long FT_Pos
Definition: ftimage.h:58
unsigned char pixel_mode
Definition: ftimage.h:268
unsigned int rows
Definition: ftimage.h:263
#define error(str)
Definition: mkdosfs.c:1605
signed int FT_Int
Definition: fttypes.h:220
FT_GlyphSlotRec root
Definition: pfrobjs.h:53
FT_Glyph_Metrics metrics
Definition: freetype.h:1916
#define PFR_BITMAP_2BYTE_SIZE
Definition: pfrtypes.h:110
FT_Fixed linearHoriAdvance
Definition: freetype.h:1917
GLdouble n
Definition: glext.h:7729
#define PFR_BITMAP_3BYTE_OFFSET
Definition: pfrtypes.h:111
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
#define FT_TRACE1(varformat)
Definition: ftdebug.h:158
#define FT_ERROR(varformat)
Definition: ftdebug.h:181
unsigned char FT_Byte
Definition: fttypes.h:154
#define FT_THROW(e)
Definition: ftdebug.h:213
FT_Int bitmap_left
Definition: freetype.h:1924
#define PFR_BITMAP_2BYTE_CHARCODE
Definition: pfrtypes.h:109
FT_Int bitmap_top
Definition: freetype.h:1925
FT_MulDiv(FT_Long a, FT_Long b, FT_Long c)
Definition: ftcalc.c:416
ft_glyphslot_alloc_bitmap(FT_GlyphSlot slot, FT_ULong size)
Definition: ftobjs.c:478
GLsizeiptr size
Definition: glext.h:5919
#define PFR_FLAG_INVERT_BITMAP
Definition: pfrtypes.h:73
#define FT_INT_MIN
Definition: ftstdlib.h:64
static void Exit(void)
Definition: sock.c:1331
#define FT_ERR_EQ(x, e)
Definition: fttypes.h:591
#define for
Definition: utility.h:88
Definition: parse.h:22
static FT_Error pfr_load_bitmap_metrics(FT_Byte **pdata, FT_Byte *limit, FT_Long scaled_advance, FT_Long *axpos, FT_Long *aypos, FT_UInt *axsize, FT_UInt *aysize, FT_Long *aadvance, FT_UInt *aformat)
Definition: pfrsbit.c:398
GLenum GLsizei len
Definition: glext.h:6722
#define FT_BOOL(x)
Definition: fttypes.h:578
_STLP_MOVE_TO_STD_NAMESPACE void _STLP_CALL advance(_InputIterator &__i, _Distance __n)
FT_Bitmap bitmap
Definition: freetype.h:1923
#define FT_FRAME_EXIT()
Definition: ftstream.h:517
#define FT_STREAM_SEEK(position)
Definition: ftstream.h:489
FT_Glyph_Format format
Definition: freetype.h:1921
signed long FT_Fixed
Definition: fttypes.h:288
unsigned int FT_UInt
Definition: fttypes.h:231
int pitch
Definition: ftimage.h:265
static void pfr_lookup_bitmap_data(FT_Byte *base, FT_Byte *limit, FT_UInt count, FT_UInt *flags, FT_UInt char_code, FT_ULong *found_offset, FT_ULong *found_size)
Definition: pfrsbit.c:277
typedefFT_BEGIN_HEADER struct PFR_FaceRec_ * PFR_Face
Definition: pfrobjs.h:27
#define FT_FRAME_ENTER(size)
Definition: ftstream.h:512
#define FT_INT_MAX
Definition: ftstdlib.h:63
static FT_Error pfr_load_bitmap_bits(FT_Byte *p, FT_Byte *limit, FT_UInt format, FT_Bool decreasing, FT_Bitmap *target)
Definition: pfrsbit.c:533
GLfloat GLfloat p
Definition: glext.h:8902
#define FT_PIX_ROUND(x)
Definition: ftobjs.h:93
GLenum GLuint GLint GLenum face
Definition: glext.h:7025
unsigned int width
Definition: ftimage.h:264

Referenced by pfr_slot_load().