Code: Alles auswählen
;Ascii Tabelle, PB 4.60 Windows Vista x86 10.08.2012 HJ Bremer
Enumeration
#window
#status
#canvas
#scroll
#image1
#image2
#container
#liste
#combosize
#combostyle
#fontmuster
EndEnumeration
Enumeration
#font0
#font1
#font2
#font3
EndEnumeration
#abstand = 4
EnableExplicit
Procedure.i MakeImage(fontname$, fontsize, fontstyle, rows = 16)
;cols = jede Zeile besteht aus 16 Spalten, genannt Box
;rows = Anzahl Zeilen, 14 Zeilen * 16 ergibt Ascii 32 - 255, darf > 14 sein
;charnr = Startwert ist Ascii 31, wird in der Schleife um 1 erhöht, dann 32
Protected cols = 16
Protected charnr = 31
Protected imgbr, imghh, boxbr, boxhh
Protected char$, charbr, charhh, farbe, x, y, posx, posy
Protected i, j, info$
Protected minbr = 9999, maxbr = 0, minhh = 9999, maxhh = 0
SetGadgetState(#fontmuster, #PB_Checkbox_Unchecked)
LoadFont(#font2, fontname$, fontsize, fontstyle)
StatusBarText(#status, 1, "Size: " + Str(fontsize))
StatusBarText(#status, 2, fontname$)
;-boxbr + hh, minbr + maxbr ermitteln
StartDrawing(CanvasOutput(#canvas))
DrawingFont(FontID(#font1))
boxhh = TextHeight("X")
boxbr = TextWidth("000") + #abstand + #abstand
DrawingFont(FontID(#font2))
boxhh + TextHeight("Xg")
boxhh + (#abstand * 3)
For j = 32 To 255
charbr = TextWidth(Chr(j))
charhh = TextHeight(Chr(j))
If boxbr < charbr: boxbr = charbr: EndIf
If charbr
If charbr > maxbr: maxbr = charbr: EndIf
If charbr < minbr: minbr = charbr: EndIf
EndIf
Next
boxbr + #abstand + #abstand
info$ = "Höhe: " + Str(charhh) + " | "
If minbr = maxbr
info$ + "Fix Breite: " + Str(minbr)
Else
info$ + "Breite: " + Str(minbr) + " - " + Str(maxbr)
EndIf
StatusBarText(#status, 0, info$)
StopDrawing()
;-Image erstellen
imgbr = (boxbr * cols) - 5
imghh = (boxhh * rows)
CreateImage(#image1, imgbr, imghh)
StartDrawing(ImageOutput(#image1))
Box(0, 0, imgbr, imghh, #Yellow)
DrawingMode(#PB_2DDrawing_Transparent)
x = #abstand: y = #abstand
For i = 1 To rows
For j = 1 To cols
;Rahmen
Box(x, y, boxbr, boxhh, #Black)
Box(x + 1, y + 1, boxbr - 2, boxhh - 2, #White)
charnr + 1
;AsciiNr als Überschrift in Box
DrawingFont(FontID(#font1))
char$ = RSet(Str(charnr), 3, "0")
If charnr > 999: char$ = RSet(Str(charnr), 4, "0"): EndIf ;für Erweiterung
charbr = TextWidth(char$)
charhh = TextHeight(char$)
posx = (boxbr - charbr) / 2
posy = #abstand
DrawText(x + posx, y + posy, char$, #Black)
;AsciiZeichen
DrawingFont(FontID(#font2))
char$ = Chr(charnr)
charbr = TextWidth(char$)
posx = (boxbr - charbr) / 2
posy + charhh + #abstand
farbe = #Blue
If charnr > 255: farbe = $555555: EndIf
DrawText(x + posx, y + posy, char$, farbe)
;Spalte nächste Box
x + boxbr - 1
Next
x = #abstand ;Spalte zurücksetzen
y + boxhh - 1 ;nächste Zeile
Next
StopDrawing()
;-Resizen
ResizeGadget(#canvas, 0, 0, ImageWidth(#image1), ImageHeight(#image1))
SetGadgetAttribute(#canvas, #PB_Canvas_Image, ImageID(#image1))
ResizeGadget(#scroll, 0, 0, ImageWidth(#image1) + 21, WindowHeight(#window) - StatusBarHeight(#status))
SetGadgetAttribute(#scroll, #PB_ScrollArea_InnerWidth, imgbr)
SetGadgetAttribute(#scroll, #PB_ScrollArea_InnerHeight, imghh)
ResizeWindow(#window, #PB_Ignore, #PB_Ignore, GadgetWidth(#scroll) + GadgetWidth(#container), #PB_Ignore)
ResizeGadget(#container, GadgetWidth(#scroll), #PB_Ignore, #PB_Ignore, #PB_Ignore)
EndProcedure
Procedure.i MakeImage2(fontsize, fontstyle = 0)
StatusBarText(#status, 2, "bitte warten")
Static oldsize, oldstyle
If (oldsize <> fontsize) Or (oldstyle <> fontstyle)
oldsize = fontsize
oldstyle = fontstyle
;Font für FontNamen
Select fontsize
Case 6 To 9: LoadFont(#font3, "Arial", fontsize - 1)
Case 10 To 12: LoadFont(#font3, "Arial", fontsize - 2)
Case 13 To 14: LoadFont(#font3, "Arial", fontsize - 3)
Case 15 To 18: LoadFont(#font3, "Arial", fontsize - 4)
EndSelect
Protected fontanz = CountGadgetItems(#liste)
Protected imgbr, imghh
Protected j, name$, char$, charbr, charhh, minbr, farbe, x, y
Protected Dim fontpbnr(fontanz), Dim fontname.s(fontanz)
For j = 1 To fontanz
fontname(j) = GetGadgetItemText(#liste, j - 1)
fontpbnr(j) = LoadFont(#PB_Any, fontname(j), fontsize, fontstyle)
Next
;-ImageGröße
imgbr = GadgetWidth(#canvas)
imghh = #abstand
char$ = "Test"
StartDrawing(WindowOutput(#window))
For j = 1 To fontanz
DrawingFont(FontID(fontpbnr(j)))
charhh = TextHeight(char$)
DrawingFont(FontID(#font3))
charbr = TextWidth(fontname(j))
If minbr < charbr: minbr = charbr: EndIf
imghh + charhh + #abstand
Next
imghh + #abstand
StopDrawing()
;-Image beschreiben
CreateImage(#image2, imgbr, imghh)
x = #abstand
y = #abstand
char$ = "Dies ist ein Test"
StartDrawing(ImageOutput(#image2))
DrawingMode(#PB_2DDrawing_Transparent)
Box(0, 0, imgbr, imghh, $FEFEFD)
For j = 1 To fontanz
DrawingFont(FontID(#font3))
DrawText(x, y , fontname(j), $002D00)
DrawingFont(FontID(fontpbnr(j)))
DrawText(x + minbr + 10, y, char$, $930000)
charhh = TextHeight(char$)
Line(1, y + charhh + 2, imgbr - 8, 1, $EEEEEE)
y + charhh + #abstand
Next
StopDrawing()
For j = 1 To fontanz: FreeFont(fontpbnr(j)): Next
EndIf
;-Resizen
ResizeGadget(#canvas, 0, 0, ImageWidth(#image2), ImageHeight(#image2))
SetGadgetAttribute(#canvas, #PB_Canvas_Image, ImageID(#image2))
ResizeGadget(#scroll, 0, 0, ImageWidth(#image2) + 21, WindowHeight(#window) - StatusBarHeight(#status))
SetGadgetAttribute(#scroll, #PB_ScrollArea_InnerWidth, ImageWidth(#image2))
SetGadgetAttribute(#scroll, #PB_ScrollArea_InnerHeight, ImageHeight(#image2))
StatusBarText(#status, 2, "")
EndProcedure
Procedure.i EnumFontsProc(*lf.LOGFONT, *tm.TEXTMETRIC, fonttype, liste)
AddGadgetItem(liste, -1, PeekS(@*lf\lfFaceName))
ProcedureReturn #True
EndProcedure
Procedure.i EnumFonts(liste, name$)
Protected dc = GetDC_(0)
EnumFonts_(dc, 0, @EnumFontsProc(), liste)
ReleaseDC_(0, dc)
Protected j, anz = CountGadgetItems(liste) - 1
Protected Dim text$(anz)
For j = 0 To anz: text$(j) = GetGadgetItemText(liste, j): Next
SortArray(text$(), #PB_Sort_Ascending )
ClearGadgetItems(liste)
For j = 0 To anz
AddGadgetItem(liste, -1, text$(j))
If text$(j) = name$: SetGadgetState(liste, j): EndIf
Next
EndProcedure
Procedure.i Mainwindow()
Protected fontname$ = "Arial" ;"Wingdings"
Protected fontsize = 10
Protected fontstyle = 0
LoadFont(#font0, "Arial", 9) ;Font Button und Liste
LoadFont(#font1, "Arial", 8) ;Font AsciiNr im Image
SetGadgetFont(#PB_Default, FontID(#font0))
Protected j, event, mem
Protected winbr = 700
Protected winhh = 450
Protected flags = #PB_Window_SystemMenu|#PB_Window_Invisible|#PB_Window_MinimizeGadget
OpenWindow(#window, 150, 150, winbr, winhh, "Ascii - Tabelle", flags)
CreateStatusBar(#status, WindowID(#window))
AddStatusBarField(#PB_Ignore)
AddStatusBarField(#PB_Ignore)
AddStatusBarField(150)
ScrollAreaGadget(#scroll, 0, 0, 0, 0, 0, 0)
CanvasGadget(#canvas, 0, 0, 0, 0, #PB_Canvas_Border)
CloseGadgetList()
ContainerGadget(#container, 0, 0, 150, winhh - StatusBarHeight(#status), #PB_Container_Single)
ListViewGadget(#liste, 2, 0, 146, winhh - 105)
ComboBoxGadget(#combosize, 2, GadgetHeight(#liste) + 5, 145, 22)
ComboBoxGadget(#combostyle, 2, GadgetHeight(#liste) + 30, 145, 22)
CheckBoxGadget(#fontmuster, 2, GadgetHeight(#liste) + 55, 145, 22, "alle Fonts zeigen")
For j = 6 To 18: AddGadgetItem(#combosize, -1, "Size " + Str(j)): Next
AddGadgetItem(#combostyle, -1, "Normal")
AddGadgetItem(#combostyle, -1, "Bold")
AddGadgetItem(#combostyle, -1, "Italic")
AddGadgetItem(#combostyle, -1, "Underline")
AddGadgetItem(#combostyle, -1, "StrikeOut")
CloseGadgetList()
;Infotext Combos, ab Vista
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
Select OSVersion()
Case #PB_OS_Windows_Vista To #PB_OS_Windows_Future
mem = AllocateMemory(60)
PokeS(mem, "Fontsize ändern", -1, #PB_Unicode)
SendMessage_(GadgetID(#combosize), #CB_SETCUEBANNER, 0, mem)
PokeS(mem, "Fontstyle ändern", -1, #PB_Unicode)
SendMessage_(GadgetID(#combostyle), #CB_SETCUEBANNER, 0, mem)
EndSelect
CompilerEndIf
;-Start
EnumFonts(#liste, fontname$)
MakeImage(fontname$, fontsize, fontstyle)
HideWindow(#window, 0)
SetActiveGadget(#liste)
Repeat: event = WaitWindowEvent()
If event = #PB_Event_Gadget
Select EventGadget()
Case #liste
fontname$ = GetGadgetItemText(#liste, GetGadgetState(#liste))
MakeImage(fontname$, fontsize, fontstyle)
Case #combosize
fontsize = Val(Right(GetGadgetItemText(#combosize, GetGadgetState(#combosize)), 2))
MakeImage(fontname$, fontsize, fontstyle)
Case #combostyle
Select GetGadgetState(#combostyle)
Case 1: fontstyle = #PB_Font_Bold
Case 2: fontstyle = #PB_Font_Italic
Case 3: fontstyle = #PB_Font_Underline
Case 4: fontstyle = #PB_Font_StrikeOut
Default: fontstyle = 0
EndSelect
MakeImage(fontname$, fontsize, fontstyle)
Case #fontmuster
If GetGadgetState(#fontmuster) = #PB_Checkbox_Checked
MakeImage2(fontsize, fontstyle)
Else
MakeImage(fontname$, fontsize, fontstyle)
EndIf
EndSelect
EndIf
Until event = #PB_Event_CloseWindow
EndProcedure
Mainwindow()