2
0
Эх сурвалжийг харах

Changes to support font rendering enhancements.

Brucey 11 сар өмнө
parent
commit
98335a9672

+ 26 - 3
font.mod/font.bmx

@@ -14,9 +14,30 @@ ModuleInfo "History: Module is now SuperStrict"
 ModuleInfo "History: 1.05 Release"
 ModuleInfo "History: 1.05 Release"
 ModuleInfo "History: Modified interface for improved unicode support"
 ModuleInfo "History: Modified interface for improved unicode support"
 
 
-Const BOLDFONT:Int=1
-Const ITALICFONT:Int=2
-Const SMOOTHFONT:Int=4
+Const BOLDFONT:Int=  $001
+Const ITALICFONT:Int=$002
+Const SMOOTHFONT:Int=$004
+
+Const SMALLCAPSFONT:Int=              $0000100
+Const ALLSMALLCAPSFONT:Int=           $0000200
+Const LIGATURESFONT:Int=              $0000400
+Const DISCRETIONARYLIGATURESFONT:Int= $0000800
+Const OLDSTYLEFIGURESFONT:Int=        $0001000
+Const TABULARFIGURESFONT:Int=         $0002000
+Const FRACTIONSFONT:Int=              $0004000
+Const SUPERSCRIPTFONT:Int=            $0008000
+Const SUBSCRIPTFONT:Int=              $0010000
+Const SWASHESFONT:Int=                $0020000
+Const STYLISTICALTERNATESFONT:Int=    $0040000
+Const CONTEXTUALALTERNATESFONT:Int=   $0080000
+Const HISTORICALFORMSFONT:Int=        $0100000
+Const DENOMINATORSFONT:Int=           $0200000
+Const NUMERATORFONT:Int=              $0400000
+Const LININGFIGURESFONT:Int=          $0800000
+Const SCIENTIFICINFERIORSFONT:Int=    $1000000
+Const PROPORTIONALFIGURESFONT:Int=    $2000000
+Const KERNFONT:Int=                   $4000000
+Const ZEROFONT:Int=                   $8000000
 
 
 Type TGlyph
 Type TGlyph
 	
 	
@@ -24,6 +45,7 @@ Type TGlyph
 
 
 	Method Advance:Float() Abstract
 	Method Advance:Float() Abstract
 	Method GetRect( x:Int Var,y:Int Var,width:Int Var,height:Int Var ) Abstract
 	Method GetRect( x:Int Var,y:Int Var,width:Int Var,height:Int Var ) Abstract
+	Method Index:Int() Abstract
 
 
 End Type
 End Type
 
 
@@ -34,6 +56,7 @@ Type TFont
 	Method CountGlyphs:Int() Abstract
 	Method CountGlyphs:Int() Abstract
 	Method CharToGlyph:Int( char:Int ) Abstract
 	Method CharToGlyph:Int( char:Int ) Abstract
 	Method LoadGlyph:TGlyph( index:Int ) Abstract
 	Method LoadGlyph:TGlyph( index:Int ) Abstract
+	Method LoadGlyphs:TGlyph[]( text:String ) Abstract
 
 
 End Type
 End Type
 
 

+ 37 - 16
freetypefont.mod/freetypefont.bmx

@@ -49,6 +49,7 @@ Type TFreeTypeGlyph Extends TGlyph
 
 
 	Field _pixmap:TPixmap
 	Field _pixmap:TPixmap
 	Field _advance:Float,_x:Int,_y:Int,_w:Int,_h:Int
 	Field _advance:Float,_x:Int,_y:Int,_w:Int,_h:Int
+	Field _index:Int
 	
 	
 	Method Pixels:TPixmap() Override
 	Method Pixels:TPixmap() Override
 		If _pixmap Return _pixmap
 		If _pixmap Return _pixmap
@@ -67,6 +68,10 @@ Type TFreeTypeGlyph Extends TGlyph
 		h=_h
 		h=_h
 	End Method
 	End Method
 
 
+	Method Index:Int() Override
+		Return _index
+	End Method
+
 End Type
 End Type
 
 
 Type TFreeTypeFont Extends BRL.Font.TFont
 Type TFreeTypeFont Extends BRL.Font.TFont
@@ -111,6 +116,7 @@ Type TFreeTypeFont Extends BRL.Font.TFont
 		If glyph Return glyph
 		If glyph Return glyph
 
 
 		glyph=New TFreeTypeGlyph
 		glyph=New TFreeTypeGlyph
+		glyph._index=index
 		_glyphs[index]=glyph
 		_glyphs[index]=glyph
 		
 		
 		If FT_Load_Glyph( _ft_face,index+1,FT_LOAD_RENDER ) Return glyph
 		If FT_Load_Glyph( _ft_face,index+1,FT_LOAD_RENDER ) Return glyph
@@ -162,16 +168,43 @@ Type TFreeTypeFont Extends BRL.Font.TFont
 		Return glyph
 		Return glyph
 
 
 	End Method
 	End Method
+
+	Method LoadGlyphs:TGlyph[]( text:String )
+		Throw "Not supported"
+	End Method
 	
 	
 	Function Load:TFreeTypeFont( src:Object,size:Int,style:Int )
 	Function Load:TFreeTypeFont( src:Object,size:Int,style:Int )
 
 
+		Local buf:Byte[]
+				
+		Local ft_face:Byte Ptr = LoadFace(src, size, style, buf)
+
+		If Not ft_face Then
+			Return Null
+		End If
+		
+		Local ft_size:Byte Ptr = bmx_freetype_Face_size(ft_face)
+		
+		Local font:TFreeTypeFont=New TFreeTypeFont
+		font._ft_face=ft_face
+		font._style=style
+		font._height=bmx_freetype_Size_height(ft_size) Sar 6
+		font._ascend=bmx_freetype_Size_ascend(ft_size) Sar 6
+		font._descend=bmx_freetype_Size_descend(ft_size) Sar 6
+		font._glyphs=New TFreeTypeGlyph[bmx_freetype_Face_numglyphs(ft_face)]
+		font._buf=buf
+		
+		Return font
+	
+	End Function
+
+	Function LoadFace:Byte Ptr( src:Object,size:Int,style:Int, buf:Byte[] Var )
+
 		Global ft_lib:Byte Ptr
 		Global ft_lib:Byte Ptr
 		
 		
 		If Not ft_lib
 		If Not ft_lib
 			If FT_Init_FreeType( Varptr ft_lib ) Return Null
 			If FT_Init_FreeType( Varptr ft_lib ) Return Null
 		EndIf
 		EndIf
-
-		Local buf:Byte[]
 				
 				
 		Local ft_face:Byte Ptr
 		Local ft_face:Byte Ptr
 
 
@@ -241,20 +274,8 @@ Type TFreeTypeFont Extends BRL.Font.TFont
 			FT_Done_Face ft_face
 			FT_Done_Face ft_face
 			Return Null
 			Return Null
 		EndIf
 		EndIf
-		
-		Local ft_size:Byte Ptr = bmx_freetype_Face_size(ft_face)
-		
-		Local font:TFreeTypeFont=New TFreeTypeFont
-		font._ft_face=ft_face
-		font._style=style
-		font._height=bmx_freetype_Size_height(ft_size) Sar 6
-		font._ascend=bmx_freetype_Size_ascend(ft_size) Sar 6
-		font._descend=bmx_freetype_Size_descend(ft_size) Sar 6
-		font._glyphs=New TFreeTypeGlyph[bmx_freetype_Face_numglyphs(ft_face)]
-		font._buf=buf
-		
-		Return font
-	
+
+		Return ft_face
 	End Function
 	End Function
 
 
 End Type
 End Type

+ 73 - 18
max2d.mod/imagefont.bmx

@@ -34,6 +34,7 @@ Type TImageFont
 	Field _src_font:TFont
 	Field _src_font:TFont
 	Field _glyphs:TImageGlyph[]
 	Field _glyphs:TImageGlyph[]
 	Field _imageFlags:Int
 	Field _imageFlags:Int
+	Field _style:Int
 
 
 	Method Style:Int()
 	Method Style:Int()
 		If _src_font Return _src_font.Style()
 		If _src_font Return _src_font.Style()
@@ -78,29 +79,82 @@ Type TImageFont
 		Return glyph
 		Return glyph
 		
 		
 	End Method
 	End Method
-	
-	Method Draw( text:String,x:Float,y:Float,ix:Float,iy:Float,jx:Float,jy:Float )
+
+	Method LoadGlyphs:TImageGlyph[]( text:String )
+
+		Local src_glyph:TGlyph[]=_src_font.LoadGlyphs( text )
+
+		Local glyphs:TImageGlyph[]=New TImageGlyph[text.length]
 
 
 		For Local i:Int=0 Until text.length
 		For Local i:Int=0 Until text.length
+			Local src:TGlyph=src_glyph[i]
+
+			Local glyph:TImageGlyph=New TImageGlyph
+			glyphs[i]=glyph
+
+			If src Then
+				Local index:Int = src.Index()
+				Local cachedGlyph:TImageGlyph = _glyphs[index]
+
+				If cachedGlyph Then
+					glyph._image = cachedGlyph._image
+				End If
 		
 		
-			Local n:Int=CharToGlyph( text[i] )
-			If n<0 Continue
-			
-			Local glyph:TImageGlyph=LoadGlyph(n)
-			Local image:TImage=glyph._image
+				glyph._advance=src.Advance()
+				src.GetRect glyph._x,glyph._y,glyph._w,glyph._h
+				If Not glyph._image
+					Local pixmap:TPixmap=TPixmap( src.Pixels() )
+					If pixmap Then
+						glyph._image=TImage.Load( pixmap.Copy(),_imageFlags,0,0,0 )
+					End If
+				End If
+			End If
+		Next
+
+		Return glyphs
+	End Method
+	
+	Method Draw( text:String,x:Float,y:Float,ix:Float,iy:Float,jx:Float,jy:Float )
+
+		If Not (_style & KERNFONT) Then
+			For Local i:Int=0 Until text.length
 			
 			
-			If image
-				Local frame:TImageFrame=image.Frame(0)
-				If frame
-					Local tx:Float=glyph._x*ix+glyph._y*iy
-					Local ty:Float=glyph._x*jx+glyph._y*jy			
-					frame.Draw 0,0,image.width,image.height,x+tx,y+ty,0,0,image.width,image.height
+				Local n:Int=CharToGlyph( text[i] )
+				If n<0 Continue
+				
+				Local glyph:TImageGlyph=LoadGlyph(n)
+				Local image:TImage=glyph._image
+				
+				If image
+					Local frame:TImageFrame=image.Frame(0)
+					If frame
+						Local tx:Float=glyph._x*ix+glyph._y*iy
+						Local ty:Float=glyph._x*jx+glyph._y*jy			
+						frame.Draw 0,0,image.width,image.height,x+tx,y+ty,0,0,image.width,image.height
+					EndIf
 				EndIf
 				EndIf
-			EndIf
-			
-			x:+glyph._advance*ix
-			y:+glyph._advance*jx
-		Next
+				
+				x:+glyph._advance*ix
+				y:+glyph._advance*jx
+			Next
+		Else
+			Local glyphs:TImageGlyph[] = LoadGlyphs( text )
+
+			For Local i:Int=0 Until glyphs.length
+				Local glyph:TImageGlyph=glyphs[i]
+				Local image:TImage=glyph._image
+				If image
+					Local frame:TImageFrame=image.Frame(0)
+					If frame
+						Local tx:Float=glyph._x*ix+glyph._y*iy
+						Local ty:Float=glyph._x*jx+glyph._y*jy			
+						frame.Draw 0,0,image.width,image.height,x+tx,y+ty,0,0,image.width,image.height
+					EndIf
+				EndIf
+				x:+glyph._advance*ix
+				y:+glyph._advance*jx
+			Next
+		End If
 		
 		
 	End Method
 	End Method
 	
 	
@@ -112,6 +166,7 @@ Type TImageFont
 		Local font:TImageFont=New TImageFont
 		Local font:TImageFont=New TImageFont
 		font._src_font=src
 		font._src_font=src
 		font._glyphs=New TImageGlyph[src.CountGlyphs()]
 		font._glyphs=New TImageGlyph[src.CountGlyphs()]
+		font._style=style
 		If style & SMOOTHFONT font._imageFlags=FILTEREDIMAGE|MIPMAPPEDIMAGE
 		If style & SMOOTHFONT font._imageFlags=FILTEREDIMAGE|MIPMAPPEDIMAGE
 		
 		
 		Return font
 		Return font