SpeedText ( Beta )

Blitz3D Forums/Blitz3D Userlibs/SpeedText ( Beta )

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

MAV after Graphics3D command (on my worker computer. On home comp. all well) :(

>> [real name].ttf
He he :) Take name of the font from TTF-file! Example (PureBasic syntax):


;//This is TTF file header
Structure TT_OFFSET_TABLE
     uMajorVersion.w
     uMinorVersion.w
     uNumOfTables.w
     uSearchRange.w
     uEntrySelector.w
     uRangeShift.w
EndStructure


; //Tables in TTF file And there placement And name (tag)
Structure TT_TABLE_DIRECTORY
     szTag.s{4}		; //table name
     uCheckSum.l		; //Check sum
     uOffset.l			; //Offset from beginning of file
     uLength.l			; //length of the table in bytes
EndStructure


; //Header of names table
Structure TT_NAME_TABLE_HEADER
    uFSelector.w		; //format selector. Always 0
    uNRCount.w			; //Name Records count
    uStorageOffset.w	; //Offset for strings storage, from start of the table
EndStructure


; //Record in names table
Structure TT_NAME_RECORD
    uPlatformID.w
    uEncodingID.w
    uLanguageID.w
    uNameID.w
    uStringLength.w
    uStringOffset.w		; //from start of storage area
EndStructure


Procedure.l SWAPWORD(x.w)
	Protected b0.l, b1.l
	b0 = ( x >> 8 ) & $000000FF
	b1 = ( x << 8 ) & $0000FF00 
	ProcedureReturn ( b0 | b1 )
EndProcedure


Procedure.l SWAPLONG (x.l)
	Protected b0.l, b1.l, b2.l, b3.l
	b0 = (x >> 24 ) & $000000FF
	b1 = (x >> 8 ) & $0000FF00 
	b2 = (x << 8 ) & $00FF0000
	b3 = (x << 24 ) & $FF000000
	ProcedureReturn ( b0 | b1 | b2 | b3 )
EndProcedure


Procedure.s GetFontNameFromFileEx(path.s, id.l)
	Protected csRetVal.s
	Protected s.s
	Protected i.l, iq.l
	Protected ttOffsetTable.TT_OFFSET_TABLE
	Protected tblDir.TT_TABLE_DIRECTORY
	Protected ttNTHeader.TT_NAME_TABLE_HEADER
	Protected bFound.l, nPos.l


	If ReadFile(0,path)
		; //Define And Read file header
		ReadData(0,@ttOffsetTable,SizeOf(TT_OFFSET_TABLE))
		
		; //remember To rearrange bytes in the field you gonna use
	    ttOffsetTable\uNumOfTables = SWAPWORD(ttOffsetTable\uNumOfTables);
	    ttOffsetTable\uMajorVersion = SWAPWORD(ttOffsetTable\uMajorVersion);
	    ttOffsetTable\uMinorVersion = SWAPWORD(ttOffsetTable\uMinorVersion);

		; TTF(TrueType) or OTF(OpenType)
		If ((ttOffsetTable\uMajorVersion & $FFFF)=1 And (ttOffsetTable\uMinorVersion & $FFFF)=0) Or ((ttOffsetTable\uMajorVersion & $FFFF)=$4F54 And (ttOffsetTable\uMinorVersion & $FFFF)=$544F)	; //check is this is a true type font And the version is 1.0
	
			bFound = #False
			
			iq = (ttOffsetTable\uNumOfTables & $FFFF)-1
			For i=0 To iq
				ReadData(0,@tblDir, SizeOf(TT_TABLE_DIRECTORY))
				If LCase(tblDir\szTag)="name"
					bFound = #True
					tblDir\uLength = SWAPLONG(tblDir\uLength)
					tblDir\uOffset = SWAPLONG(tblDir\uOffset)
					Break
				EndIf
			Next
	
			If bFound
				FileSeek(0,tblDir\uOffset )
				ReadData(0,@ttNTHeader, SizeOf(TT_NAME_TABLE_HEADER))
			
	
	 			ttNTHeader\uNRCount = SWAPWORD(ttNTHeader\uNRCount);
	 			ttNTHeader\uStorageOffset = SWAPWORD(ttNTHeader\uStorageOffset);
	 			ttRecord.TT_NAME_RECORD
	 			bFound = #False;
	
	
				iq = (ttNTHeader\uNRCount & $FFFF) - 1
				For i=0 To iq
					ReadData(0,@ttRecord, SizeOf(TT_NAME_RECORD))
					ttRecord\uNameID = SWAPWORD(ttRecord\uNameID)
	
					If (ttRecord\uNameID & $FFFF) = id
	
	 					ttRecord\uStringLength = SWAPWORD(ttRecord\uStringLength);
	 					ttRecord\uStringOffset = SWAPWORD(ttRecord\uStringOffset);
	 					
	 					nPos = Loc(0)	
	 					FileSeek(0, tblDir\uOffset + (ttRecord\uStringOffset & $FFFF) + (ttNTHeader\uStorageOffset & $FFFF) )
	 							
	 					s.s = Space( ttRecord\uStringLength & $FFFF )		
						ReadData(0,@s, (ttRecord\uStringLength & $FFFF) )
						s=Trim(s)
						
						If Len(s)>0
							csRetVal=s
							Break					
						EndIf					
						
						FileSeek(0, nPos) 
					EndIf
							
				Next
	
			EndIf
			
		EndIf

		CloseFile(0)
	EndIf
	
	ProcedureReturn csRetVal
EndProcedure


Procedure.s GetFontNameFromFile(path.s)

	;USE ID = 1	  ==  family name

	; id:
	; 0 - Copyright
	; 1 - Family Name
	; 2 - Style
	; 3 - ? Name Full
	; 4 - Name (Full)
	; 5 - Version
	; 6 - PostScript Name
	; 7 - Trademark

	ProcedureReturn GetFontNameFromFileEx(path,1)
EndProcedure



See my FastText library, there no such problem.