Seite 2 von 4

Verfasst: 11.03.2005 16:12
von Criss
@Lebostein

Absolute hammerharte Spitze!!! Geniales Tool!

Verfasst: 11.03.2005 17:27
von SoS
Lebostein hat geschrieben:
DarkDragon hat geschrieben:Hmm... genau das gibts zwar schon lange(mit 255 Zeichen oder 128 Zeichen wählbar), aber was solls, danke.
Meinst du damit das Erstellen eines Fonts aus einer TTF-Schriftart? Das hab ich nur vorläufig 'so zum Spaß an der Freude' mit eingebaut. Da gibt es sicher bessere Programme, da geb ich dir recht. Derzeit ist es nur ein stumpfes Schreiben von Buchstaben auf ein Image, d.h ich öffne die TTF nicht binär sondern nutze ein paar einfache PB-Drawing Funktionen. Vielleicht bastel ich da noch ein wenig dran, aber es ist nur eine Zusatzfunktion, die eigentlich nichts mit dem Sinn meines Programmes zu tun hat.
:allright: wer hier was anderes behauptet dem ist halt nicht mehr zu helfen :lol:

wie wäre es bei den ttf-fonts alle pixel die nicht schwarz sind durch eine vorher definibare textur zu ersetzen ? klar geht das nur bei grossen "fetten" fonts.ich glaube da kommen ganz interessante sachen dabei raus.

Verfasst: 11.03.2005 17:33
von Lebostein
Hey, das ist ne gut Idee mit den Texturen. Und optional kann man ja noch einen Schatten anbieten, der dann hinter die Buchstaben gelegt wird. Dazu muss ich mich erstmal mit dem ttf-format beschäftigen. Sos hat mir ja schon Code zu dem Thema zugeschickt, danke nochmal. Vielleicht guck ich mir das mal am Wochenende etwas näher an....

Verfasst: 12.03.2005 21:10
von Andre
Da der FontMap Editor jetzt auch im PureArea.net Showcase verfügbar ist (siehe http://www.purearea.net/pb/showcase/sho ... p=0&sort=1), solltet ihr eure positiven Kommentare natürlich auch dort in der Bewertung zeigen. :allright:

Verfasst: 16.03.2005 10:18
von Lebostein
Update!

Folgende Neuerungen im Editor:

- übersichtlichere Darstellung des Bitmap-Rasters
- im neuen Darstellungsmodus 'Clip' können die Buchstaben im Raster mit ihrer wahren Zeichenbreite dargestellt werden
- der Editor lädt nun automatisch die zum Font gehörende Grafikdatei, egal ob BMP oder PNG (BMP hat Vorrang)
- Bitmaps können nun wahlweise als BMP oder PNG gespeichert werden
- JPEG-Unterstützung vollständig entfernt, da der Einsatz eines verlustbehafteten Formates für diesen Zweck nicht sinnvoll ist
- Zoomlevel nun über ein TrackbarGadget einstellbar
- neue Infos in der Statusbar
- Editor nun im XP-Skin-Format compiliert (wer's mag....)
- Screenshot: http://home.arcor.de/tomysoft/temp/FontMap2.gif

Änderungen in der Include:

- einige kleine 'Befehlsleichen' entfernt, die unnötig waren
- Speedup für einzeilige Texte: Das unnötige Aufrufen der Funktion 'StringField()' entfällt in diesem Fall
- Buchstaben und Zeichen mit der Breite Null, bzw. nicht existierende Zeichen werden jetzt ordnungsgemäß übergangen (-> ClipSprite wird nicht mehr mit Breite = 0 ausgeführt, -> keine ungewollten Verschiebungen des virtuellen Cursors bei nicht existierenden Zeichen)
- Grafikformat der Bitmap ist nun beliebig, da beim Laden des Fonts die Dateierweiterung der Bitmap mit angegeben werden muss
---> insgesamt ist die Include kleiner und schneller geworden

Mittlerweile haben sich 28 Fonts angesammelt.... :D

Hier der Download: http://www.purearea.net/pb/showcase/show.php?id=165

Verfasst: 06.09.2007 11:13
von Rings
Irgendwann braucht jeder einmal
einen Grafischen Font auf seinem Screen
So nun auch ich, zumal der Source beiliegt.
(Ich hab kein bock auf userlibs ohne source)

Lebostein hatte das noch für 3.93 gemacht,
ich hab die includes mal eben angepasst auf v4.x
sowie mal ne Catch-Funktion mit eingebaut.

und da ich gerne gebe ,

der geänderte code hier:


Code: Alles auswählen

;---- Screen erstellen ----

InitMouse()
InitSprite()
InitKeyboard()

UsePNGImageDecoder()

OpenScreen(1024, 768, 16, "Font-Machine")

;---- Schriftarten laden ----

;NEU! Jetzt die Dateierweiterung der Bitmap mit angeben - somit kann jedes Grafikformat verwendet werden
;Das zugehörige Datenfile (*.font) wird anhand der geladenen Grafikdatei automatisch ermittelt

IncludeFile "Include\FontMapSystem.pbi"

FontID1 = FontMapLoad("Fonts\Bennyfnt.png") ;---- NEU! Hier wird z.B. eine PNG-Datei geladen
FontID2 = FontMapLoad("Fonts\Monkey1.bmp")
FontID3 = FontMapLoad("Fonts\Fugger2.bmp")
FontID4 = FontMapLoad("Fonts\Snowfont.bmp")
FontID5 = FontMapLoad("Fonts\Tentacle.bmp")
FontIDA = FontMapLoad("Fonts\Rocky.png") ;------- NEU! Hier wird z.B. eine PNG-Datei geladen
FontID6 = FontMapLoad("Fonts\AgastLarge.bmp")
FontID7 = FontMapLoad("Fonts\ComicGreen.bmp")
FontID8 = FontMapLoad("Fonts\Algonet184.bmp")

DataSection:
 Pos1:
 IncludeBinary "Fonts\CoolSpot.bmp"
 Pos2:
 IncludeBinary "Fonts\CoolSpot.font"
EndDataSection


FontID9 = FontMapCatch(?Pos1,?Pos2)
;FontID9 = FontMapLoad("Fonts\CoolSpot.bmp")
 
;---- Hauptschleife ----

text$ = "PureBasic ist klasse!" + #CR$
text$ + "Bitte mal die Zifferntasten auf" + #CR$
text$ + "dem Num-Pad ausprobieren!"

font = FontID9: col = $FFFFFF: hori = #FHC: vert = #FVC

Repeat

  ExamineMouse()
  ExamineKeyboard()
    
  ClearScreen($AA55AA)

  StartDrawing(ScreenOutput())
  LineXY(MouseX(),MouseY()-80,MouseX(),MouseY()+80, $0000FF)
  LineXY(MouseX()-80,MouseY(),MouseX()+80,MouseY(), $0000FF)
  StopDrawing()

  FontMapOutput(FontID1, "POWER OF PUREBASIC 3.93", 400, 50, #FHC, #FVT, 0)
  FontMapOutput(FontID2, Str(MouseX()) + "," + Str(MouseY()), 780, 20, #FHR, #FVT, $009CFF)
  FontMapOutput(FontID3, "Es war einmal vor langer Zeit...", 10, 110, #FHL, #FVT, 0)
  FontMapOutput(FontID3, "Ein Ring sie zu knechten, sie alle zu finden...", 40, 140, #FHL, #FVT, 0)
  FontMapOutput(FontID4, "Das ist eine Testzeile", 780, 500, #FHR, #FVB, $400CC0)
  FontMapOutput(FontID4, "Das ist eine Testzeile", 780, 540, #FHR, #FVB, $78DC68)
  FontMapOutput(FontID4, "Das ist eine Testzeile", 780, 580, #FHR, #FVB, $787488)
  FontMapOutput(FontID6, "Timer: " + Str(ElapsedMilliseconds()), 10, 535, #FHL, #FVB, $28F0D8)
  FontMapOutput(FontID7, "Datum: " + FormatDate("%dd.%mm.%yyyy", Date()), 10, 600, #FHL, #FVB, 0)
  FontMapOutput(FontID8, "WWW.PUREBASIC.COM", 400, 200, #FHC, #FVT, 0)
  FontMapOutput(FontIDA, "Mein Name ist Hase!", 10, 460, #FHL, #FVT, 0)
  FontMapOutput(FontID9, UCase("Mein Name ist Hase!"), 400, 460, #FHL, #FVT, 0)

  If KeyboardReleased(#PB_Key_Pad1): hori = #FHR: vert = #FVT: col = Random($FFFFFF): zusatz$ = #CR$ + "(rechtsbündig, obenbündig)": EndIf
  If KeyboardReleased(#PB_Key_Pad2): hori = #FHC: vert = #FVT: col = Random($FFFFFF): zusatz$ = #CR$ + "(zentriert, obenbündig)": EndIf
  If KeyboardReleased(#PB_Key_Pad3): hori = #FHL: vert = #FVT: col = Random($FFFFFF): zusatz$ = #CR$ + "(linksbündig, obenbündig)": EndIf
  If KeyboardReleased(#PB_Key_Pad4): hori = #FHR: vert = #FVC: col = Random($FFFFFF): zusatz$ = #CR$ + "(rechtsbündig, zentriert)": EndIf
  If KeyboardReleased(#PB_Key_Pad5): hori = #FHC: vert = #FVC: col = Random($FFFFFF): zusatz$ = #CR$ + "(zentriert, zentriert)": EndIf
  If KeyboardReleased(#PB_Key_Pad6): hori = #FHL: vert = #FVC: col = Random($FFFFFF): zusatz$ = #CR$ + "(linksbündig, zentriert)": EndIf
  If KeyboardReleased(#PB_Key_Pad7): hori = #FHR: vert = #FVB: col = Random($FFFFFF): zusatz$ = #CR$ + "(rechtsbündig, untenbündig)": EndIf
  If KeyboardReleased(#PB_Key_Pad8): hori = #FHC: vert = #FVB: col = Random($FFFFFF): zusatz$ = #CR$ + "(zentriert, untenbündig)": EndIf
  If KeyboardReleased(#PB_Key_Pad9): hori = #FHL: vert = #FVB: col = Random($FFFFFF): zusatz$ = #CR$ + "(linksbündig, untenbündig)": EndIf

  If KeyboardPushed(#PB_Key_1): font = FontIDA: EndIf
  If KeyboardPushed(#PB_Key_2): font = FontID2: EndIf
  If KeyboardPushed(#PB_Key_3): font = FontID3: EndIf
  If KeyboardPushed(#PB_Key_4): font = FontID4: EndIf
  If KeyboardPushed(#PB_Key_5): font = FontID9: EndIf
  If KeyboardPushed(#PB_Key_6): font = FontID6: EndIf
  If KeyboardPushed(#PB_Key_7): font = FontID7: EndIf

  If KeyboardPushed(#PB_Key_Space): add$ = #CR$ + "eine weitere Zeile": Else: add$ = "": EndIf

  FontMapOutput(font, UCase(text$ + zusatz$ + add$), MouseX(), MouseY(), hori, vert, col)

  FlipBuffers()

Until KeyboardReleased(#PB_Key_Escape)
sowie die dazugehörige geänderte Include:

Code: Alles auswählen

;=====================================================
; Tomysoft Fontsystem Include V0.6
; 21.03.2005 by Lebostein
; 06.09.2007 by S.Rings
; Optimized for PureBasic 4.x
;=====================================================

Global FontMapCount  ;Zählt die vorhandenen Fonts

Enumeration
  #FHL               ;Ausrichtung horizontal linksbündig (LEFT)
  #FHC               ;Ausrichtung horizontal zentriert (CENTER)
  #FHR               ;Ausrichtung horizontal rechtsbündig (RIGHT)
EndEnumeration

Enumeration
  #FVT               ;Ausrichtung vertikal obenbündig (TOP)
  #FVC               ;Ausrichtung vertikal zentriert (CENTER)
  #FVB               ;Ausrichtung vertikal untenbündig (BOTTOM)
EndEnumeration

Structure FontMap
  back.l             ;Transparente Hintergrundfarbe
  over.l             ;Veränderliche Vordergrundfarbe
  wide.w             ;Globaler Zeichenabstand
  high.w             ;Globaler Zeilenabstand
  numx.w             ;Feldanzahl in x
  numy.w             ;Feldanzahl in y
  lenx.w             ;Feldbreite
  leny.w             ;Feldhöhe
  maxi.w[256]        ;Reduzierte Zeichenbreite
  posx.w[256]        ;Position x
  posy.w[256]        ;Position y
  draw.l             ;Adresse des Sprites für die Ausgabe
  copy.l             ;Adresse des Backup-Sprites
  acol.l             ;Aktuelle Farbe des Ausgabesprites
EndStructure

Global NewList FontMap.FontMap()

; Font Datei laden 
Procedure FontMapLoad(FileName$)

  ;Sprite laden und prüfen
  SpriteID = LoadSprite(#PB_Any, FileName$)
  If SpriteID = 0: ProcedureReturn #PB_Default: EndIf

  ;Datei öffnen und prüfen
  Length = Len(FileName$) - Len(GetExtensionPart(FileName$))
  FileID = ReadFile(#PB_Any, Left(FileName$, Length) + "FONT")
  If FileID = 0: FreeSprite(SpriteID): ProcedureReturn #PB_Default: EndIf

  ;Neuen Font erstellen und Daten einlesen
  LastElement(FontMap()): AddElement(FontMap())

  FontMap()\back = ReadLong(FileID )
  FontMap()\over = ReadLong(FileID )
  FontMap()\wide = ReadWord(FileID )
  FontMap()\high = ReadWord(FileID )
  FontMap()\numx = ReadWord(FileID )
  FontMap()\numy = ReadWord(FileID )
  FontMap()\lenx = ReadWord(FileID )
  FontMap()\leny = ReadWord(FileID )

  For y = 1 To FontMap()\numy
  For x = 1 To FontMap()\numx

  acode = ReadWord(FileID )
  FontMap()\maxi[acode] = ReadWord(FileID )
  FontMap()\posx[acode] = FontMap()\lenx * (x - 1)
  FontMap()\posy[acode] = FontMap()\leny * (y - 1)

  Next x
  Next y

  CloseFile(FileID)

  ;Ausgabe-Sprite initialisieren

  FontMap()\draw = SpriteID
  TransparentSpriteColor(FontMap()\draw,FontMap()\back)

  ;Backup-Sprite initialisieren (wenn Vordergrundfarbe aktiv)

  If FontMap()\over <> #PB_Default

  FontMap()\acol = FontMap()\over
  FontMap()\copy = CopySprite(FontMap()\draw, #PB_Any)
  TransparentSpriteColor(FontMap()\copy,FontMap()\over)

  EndIf

  ;Listenindex als FontID zurückgeben

  FontMapCount = CountList(FontMap())

  ProcedureReturn ListIndex(FontMap())

EndProcedure


Procedure FontMapCatch(Pos1,Pos2)

  SpriteID = CatchSprite(#PB_Any, Pos1)
  If SpriteID = 0: ProcedureReturn #PB_Default: EndIf

  ;Neuen Font erstellen und Daten einlesen

  LastElement(FontMap()): AddElement(FontMap())
  FontPos=Pos2
  FontMap()\back = PeekL(FontPos):FontPos+4;ReadLong(FileID )
  FontMap()\over = PeekL(FontPos):FontPos+4;ReadLong(FileID )
  FontMap()\wide = PeekW(FontPos):FontPos+2;ReadWord(FileID )
  FontMap()\high = PeekW(FontPos):FontPos+2;ReadWord(FileID )
  FontMap()\numx = PeekW(FontPos):FontPos+2;ReadWord(FileID )
  FontMap()\numy = PeekW(FontPos):FontPos+2;ReadWord(FileID )
  FontMap()\lenx = PeekW(FontPos):FontPos+2;ReadWord(FileID )
  FontMap()\leny = PeekW(FontPos):FontPos+2;ReadWord(FileID )

  For y = 1 To FontMap()\numy
   For x = 1 To FontMap()\numx
    Debug FontPos
    acode = PeekW(FontPos):FontPos+2;ReadWord(FileID )
    FontMap()\maxi[acode] = PeekW(FontPos):FontPos+2;ReadWord(FileID )
    FontMap()\posx[acode] = FontMap()\lenx * (x - 1)
    FontMap()\posy[acode] = FontMap()\leny * (y - 1)
   Next x
  Next y
  ;Ausgabe-Sprite initialisieren
  FontMap()\draw = SpriteID
  TransparentSpriteColor(FontMap()\draw,FontMap()\back)
  ;Backup-Sprite initialisieren (wenn Vordergrundfarbe aktiv)
  If FontMap()\over <> #PB_Default

  FontMap()\acol = FontMap()\over
  FontMap()\copy = CopySprite(FontMap()\draw, #PB_Any)
  TransparentSpriteColor(FontMap()\copy,FontMap()\over)

  EndIf
  ;Listenindex als FontID zurückgeben
  FontMapCount = CountList(FontMap())
  ProcedureReturn ListIndex(FontMap())
EndProcedure

; Länge des Textes ermitteln 
Procedure FontMapWide(FontID, Text$)
  ;FontID prüfen und auswählen
  If FontID < 0 Or FontID >= FontMapCount: ProcedureReturn 0: EndIf
  SelectElement(FontMap(), FontID)
  ;Breite des Textes berechnen
  Count = Len(Text$) - 1
  For CharIndex = 0 To Count
   ASCII = PeekB(@Text$ + CharIndex) & $FF
   If FontMap()\maxi[ASCII] = 0: Continue: EndIf
   PosiX + FontMap()\maxi[ASCII] + FontMap()\wide
  Next CharIndex
  ;Breite des Textes ausgeben
  ProcedureReturn PosiX - FontMap()\wide

EndProcedure

; Höhe des Textes ermitteln 
Procedure FontMapHigh(FontID, Text$)

  ;FontID prüfen und auswählen

  If FontID < 0 Or FontID >= FontMapCount: ProcedureReturn 0: EndIf
  SelectElement(FontMap(), FontID)

  ;Höhe des Textes berechnen

  Lines = CountString(Text$, #CR$) + 1
  PosiY = Lines * (FontMap()\leny + FontMap()\high)

  ;Höhe des Textes ausgeben

  ProcedureReturn PosiY - FontMap()\high

EndProcedure

; Text ausgeben 
Procedure FontMapOutput(FontID, Text$, PosiX, PosiY, Hori, Vert, RGB)

  ;FontID prüfen und auswählen

  If FontID < 0 Or FontID >= FontMapCount: ProcedureReturn 0: EndIf
  SelectElement(FontMap(), FontID)

  ;Sprite einfärben (wenn Vordergrundfarbe aktiv)

  If FontMap()\over <> #PB_Default And FontMap()\acol <> RGB

  UseBuffer(FontMap()\draw)
  ClearScreen(RGB )
  DisplayTransparentSprite(FontMap()\copy, 0, 0)
  UseBuffer(#PB_Default)

  FontMap()\acol = RGB: EndIf

  ;Font auf Bildschirm ausgeben

  LineCount = CountString(Text$, #CR$) + 1

  Select Vert
   Case #FVT: OutPosiY = PosiY
   Case #FVC: OutPosiY = PosiY - FontMapHigh(FontID, Text$) >> 1
   Case #FVB: OutPosiY = PosiY - FontMapHigh(FontID, Text$)
  EndSelect

  For LineIndex = 1 To LineCount
   If LineCount = 1: Line$ = Text$: Else: Line$ = StringField(Text$, LineIndex, #CR$): EndIf
   Select Hori
    Case #FHL: OutPosiX = PosiX
    Case #FHC: OutPosiX = PosiX - FontMapWide(FontID, Line$) >> 1
    Case #FHR: OutPosiX = PosiX - FontMapWide(FontID, Line$)
   EndSelect
   Count = Len(Line$) - 1
   For CharIndex = 0 To Count
    ASCII = PeekB(@Line$ + CharIndex) & $FF
    If FontMap()\maxi[ASCII] = 0: Continue: EndIf
    ClipSprite(FontMap()\draw, FontMap()\posx[ASCII], FontMap()\posy[ASCII], FontMap()\maxi[ASCII], FontMap()\leny)
    DisplayTransparentSprite(FontMap()\draw, OutPosiX, OutPosiY)
    OutPosiX + FontMap()\maxi[ASCII] + FontMap()\wide
   Next CharIndex
   OutPosiY + FontMap()\high + FontMap()\leny
  Next LineIndex
EndProcedure

danke nochmals an Lebostein für seine Arbeit.
Fliesst dann ins PBMediaPortal ein....

Verfasst: 06.09.2007 22:33
von jpd
Hi Rings,

sorry aber bin neugirig!

was ist PBMediaPortal??

Ciao
jpd

Verfasst: 07.09.2007 08:35
von Rings
jpd hat geschrieben:Hi Rings,

sorry aber bin neugirig!

was ist PBMediaPortal??

Ciao
jpd
neues projekt von mir. mehr folgt irgendwann....

Verfasst: 07.09.2007 09:08
von jpd
der name klingt schon mal interessant. :)

Verfasst: 07.09.2007 09:10
von dige
Wow, das FontMapSystem kannte ich noch gar nicht ... sehr gut gemacht!!!