Platforms to show: All Mac Windows Linux Cross-Platform
/DynaPDF/Fonts Mapping
Function:
Required plugins for this example: MBS DynaPDF Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /DynaPDF/Fonts Mapping
This example is the version from Mon, 29th Jul 2018.
Function:
Required plugins for this example: MBS DynaPDF Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /DynaPDF/Fonts Mapping
This example is the version from Mon, 29th Jul 2018.
Project "Fonts Mapping.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class MainWindow Inherits Window
Control List Inherits Listbox
ControlInstance List Inherits Listbox
End Control
EventHandler Sub Open()
dim d as new DynaPDFMBS
dim u as integer = FontCount-1
for i as integer = 0 to u
dim font as string = font(i)
List.AddRow font
dim f as DynaPDFSysFontMBS = FindBestDynaPDFFontForFont(d, font)
if f <> nil then
List.Cell(List.LastIndex,1) = f.FamilyName
List.Cell(List.LastIndex,2) = f.PostScriptName
end if
next
End EventHandler
Function FindBestDynaPDFFontForFont(d as DynaPDFMBS, font as string) As DynaPDFSysFontMBS
static cache as new Dictionary
if cache.hasKey(font) then
return cache.Value(font)
end if
dim fonts() as DynaPDFSysFontMBS = d.GetSysFontInfos
dim Best as DynaPDFSysFontMBS
dim BestIsItalic as Boolean
dim BestIsBold as Boolean
dim BestIsRegular as Boolean
for each f as DynaPDFSysFontMBS in fonts
if f.FamilyName = font or f.FullName = font then
dim Style as integer = f.Style
dim Weight as integer = d.WeightFromStyle(style)
dim IsItalic as boolean = (style and d.kfsItalic) <> 0
dim IsBold as boolean = (style and 2) <> 0
dim IsRegular as boolean = Weight = 400
if Best = nil then
Best = f
BestIsItalic = IsItalic
BestIsBold = IsBold
BestIsRegular = IsRegular
else
if IsRegular and not BestIsRegular then
// found better font which is regular
Best = f
BestIsItalic = IsItalic
BestIsBold = IsBold
BestIsRegular = IsRegular
elseif (BestIsBold or BestIsItalic) and not IsBold and not IsItalic then
// found better font which is not bold or italic
Best = f
BestIsItalic = IsItalic
BestIsBold = IsBold
BestIsRegular = IsRegular
elseif BestIsBold and not IsBold then
Best = f
BestIsItalic = IsItalic
BestIsBold = IsBold
BestIsRegular = IsRegular
elseif BestIsItalic and not IsItalic then
Best = f
BestIsItalic = IsItalic
BestIsBold = IsBold
BestIsRegular = IsRegular
end if
end if
end if
next
if best = nil then
// look for common prefix
for each f as DynaPDFSysFontMBS in fonts
if f.FamilyName.left(len(font)) = font then
dim Style as integer = f.Style
dim Weight as integer = d.WeightFromStyle(style)
dim IsItalic as boolean = (style and d.kfsItalic) <> 0
dim IsBold as boolean = (style and 2) <> 0
dim IsRegular as boolean = Weight = 400
if Best = nil then
Best = f
BestIsItalic = IsItalic
BestIsBold = IsBold
BestIsRegular = IsRegular
else
if IsRegular and not BestIsRegular then
// found better font which is regular
Best = f
BestIsItalic = IsItalic
BestIsBold = IsBold
BestIsRegular = IsRegular
elseif (BestIsBold or BestIsItalic) and not IsBold and not IsItalic then
// found better font which is not bold or italic
Best = f
BestIsItalic = IsItalic
BestIsBold = IsBold
BestIsRegular = IsRegular
elseif BestIsBold and not IsBold then
Best = f
BestIsItalic = IsItalic
BestIsBold = IsBold
BestIsRegular = IsRegular
elseif BestIsItalic and not IsItalic then
Best = f
BestIsItalic = IsItalic
BestIsBold = IsBold
BestIsRegular = IsRegular
end if
end if
end if
next
end if
cache.Value(font) = best
return best
End Function
End Class
MenuBar MainMenuBar
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem EditSeparator1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem EditSeparator2 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
End Project
See also:
The items on this page are in the following plugins: MBS DynaPDF Plugin.
