Xojo Conferences
MBSSep2018MunichDE
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/DynaPDF/Tables/Table showing all fonts
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/Tables/Table showing all fonts
This example is the version from Wed, 23th Feb 2016.
Project "Table showing all fonts.rbp"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
EventHandler Sub Open() Run quit End EventHandler
Sub Run() dim pdf as new MyDynaPDFMBS call pdf.CreateNewPDF call pdf.SetPageCoords(pdf.kpcTopDown) dim tbl as DynaPDFTableMBS = pdf.CreateTable(100, 5, 500.0, 10.0) call tbl.SetBorderWidth(-1, -1, 1.0, 1.0, 1.0, 1.0) call tbl.SetGridWidth( 0.1, 0.1) // get all fonts dim fonts() as DynaPDFSysFontMBS = pdf.GetSysFontInfos 'dim fonts() as DynaPDFSysFontMBS 'dim font as DynaPDFSysFontMBS = pdf.GetSysFontInfo 'while font <> nil 'fonts.Append font 'font = font.NextFont 'wend // make header row dim rowNum as integer = tbl.AddRow(15.0) call tbl.SetCellText rowNum, 0, pdf.ktaLeft, tbl.kcoTop, "Family Name" call tbl.SetCellText rowNum, 1, pdf.ktaLeft, tbl.kcoTop, "Full Name" call tbl.SetCellText rowNum, 2, pdf.ktaLeft, tbl.kcoTop, "PostScript Name" call tbl.SetCellText rowNum, 3, pdf.ktaLeft, tbl.kcoTop, "Style" call tbl.SetCellText rowNum, 4, pdf.ktaLeft, tbl.kcoTop, "Sample Text" // add one row for each font for each f as DynaPDFSysFontMBS in fonts rowNum = tbl.AddRow(-1.0) dim styles() as string if BitwiseAnd(f.Style, pdf.kfsItalic) <> 0 then Styles.Append "Italic" end if if BitwiseAnd(f.Style, pdf.kfsUnderlined) <> 0 then Styles.Append "Underlined" end if if BitwiseAnd(f.Style, pdf.kfsStriked) <> 0 then Styles.Append "Striked" end if if BitwiseAnd(f.Style, pdf.kfsVerticalMode) <> 0 then Styles.Append "VerticalMode" end if // Width class dim n as integer = BitwiseAnd(f.Style, &hFF00) Select case n case pdf.kfsUltraCondensed Styles.Append "UltraCondensed" case pdf.kfsExtraCondensed Styles.Append "ExtraCondensed" case pdf.kfsCondensed Styles.Append "Condensed" case pdf.kfsSemiCondensed Styles.Append "SemiCondensed" case pdf.kfsNormal Styles.Append "Normal" case pdf.kfsUltraCondensed Styles.Append "UltraCondensed" case pdf.kfsSemiExpanded Styles.Append "SemiExpanded" case pdf.kfsExpanded Styles.Append "Expanded" case pdf.kfsExtraExpanded Styles.Append "ExtraExpanded" case pdf.kfsUltraExpanded Styles.Append "UltraExpanded" case 0 // nothing else break end Select // Weight class n = BitwiseAnd(f.Style, &hFFF00000) Select case n case pdf.kfsThin Styles.Append "Thin" case pdf.kfsExtraLight Styles.Append "ExtraLight" case pdf.kfsLight Styles.Append "Light" case pdf.kfsRegular Styles.Append "Regular" case pdf.kfsMedium Styles.Append "Medium" case pdf.kfsDemiBold Styles.Append "DemiBold" case pdf.kfsBold Styles.Append "Bold" case pdf.kfsExtraBold Styles.Append "ExtraBold" case pdf.kfsBlack Styles.Append "Black" case pdf.kfsUltraBlack Styles.Append "UltraBlack" case 0 // nothing else break end Select dim familyName as string = f.FamilyName dim FullName as string = f.FullName dim PostScriptName as string = f.PostScriptName dim Style as string = join(styles, ", ") call tbl.SetCellText rowNum, 0, pdf.ktaLeft, tbl.kcoTop, FamilyName call tbl.SetCellText rowNum, 1, pdf.ktaLeft, tbl.kcoTop, FullName call tbl.SetCellText rowNum, 2, pdf.ktaLeft, tbl.kcoTop, PostScriptName call tbl.SetCellText rowNum, 3, pdf.ktaLeft, tbl.kcoTop, Style call tbl.SetCellText rowNum, 4, pdf.ktaLeft, tbl.kcoTop, "ABC abc 123 ߀ä" call tbl.SetFont(rowNum, 4, familyName, f.Style, true, pdf.kcpUnicode) next // set font size for all call tbl.SetFontSize(-1, -1, 10) // set flags for first row to make header row call tbl.SetFlags(0, -1, tbl.ktfHeaderRow) call tbl.SetFont(0, -1, "Helvetica", pdf.kfsBold, true, pdf.kcpUnicode) // Draw the table now call pdf.Append call tbl.DrawTable(50.0, 50.0, 742.0) while tbl.HaveMore call pdf.EndPage call pdf.Append call tbl.DrawTable(50.0, 50.0, 742.0) wend call pdf.EndPage // A table stores errors and warnings in the error log // write error file dim ErrorCount as integer = pdf.GetErrLogMessageCount if ErrorCount > 0 then dim f as FolderItem = SpecialFolder.Desktop.Child("test.txt") dim t as TextOutputStream = TextOutputStream.Create(f) for i as integer = 0 to ErrorCount-1 dim err as DynaPDFErrorMBS = pdf.GetErrLogMessage(i) t.WriteLine "Message: "+err.Message t.WriteLine "ObjNum: "+str(err.ObjNum) t.WriteLine "Offset: "+str(err.Offset) t.WriteLine "SrcFile: "+err.SrcFile t.WriteLine "SrcLine: "+str(err.SrcLine) t.WriteLine "" next end if // No fatal error occurred? if pdf.HaveOpenDoc then // We write the output file into the current directory. // OK, now we can open the output file. dim f as FolderItem = SpecialFolder.Desktop.Child("Table with Fonts.pdf") if not pdf.OpenOutputFile(f) then MsgBox "Failed to open output file!" end if call pdf.CloseFile f.launch end if End Sub
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&Ablage"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Bearbeiten"
MenuItem EditUndo = "&Rückgängig"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "&Ausschneiden"
MenuItem EditCopy = "&Kopieren"
MenuItem EditPaste = "&Einfügen"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "&Alles auswählen"
End MenuBar
Class MyDynaPDFMBS Inherits DynaPDFMBS
EventHandler Function Error(ErrorCode as integer, ErrorMessage as string, ErrorType as integer) As integer // output all messages on the console: System.DebugLog str(ErrorCode)+": "+ErrorMessage // and display dialog: Dim d as New MessageDialog //declare the MessageDialog object Dim b as MessageDialogButton //for handling the result d.icon=MessageDialog.GraphicCaution //display warning icon d.ActionButton.Caption="Continue" d.CancelButton.Visible=True //show the Cancel button // a warning or an error? if BitAnd(ErrorType, me.kE_WARNING) = me.kE_WARNING then // if user decided to ignore, we'll ignore if IgnoreWarnings then Return 0 d.Message="A warning occurred while processing your PDF code." // we add a third button to display all warnings d.AlternateActionButton.Caption = "Ignore warnings" d.AlternateActionButton.Visible = true else d.Message="An error occurred while processing your PDF code." end if d.Explanation = str(ErrorCode)+": "+ErrorMessage b=d.ShowModal //display the dialog Select Case b //determine which button was pressed. Case d.ActionButton Return 0 // ignore Case d.AlternateActionButton IgnoreWarnings = true Return 0 // ignore Case d.CancelButton Return -1 // stop End select End EventHandler
Property IgnoreWarnings As Boolean
End Class
End Project

See also:

Feedback, Comments & Corrections

The items on this page are in the following plugins: MBS DynaPDF Plugin.




Links
MBS Xojo Plugins