Font dosyasının özellikleri nasıl alınır?

Delphi'de kod yazma ile ilgili sorularınızı bu foruma yazabilirsiniz.
Cevapla
Sedat Atif
Üye
Mesajlar: 80
Kayıt: 18 Şub 2004 08:12
Konum: Fâni bir yerden
İletişim:

Font dosyasının özellikleri nasıl alınır?

Mesaj gönderen Sedat Atif »

Merhaba,

Font dosyalarının özellikleri nasıl alınır?

Mesela font adı, copyright notu gibi metinler oluyor font dosyalarında. Bunları nasıl öğrenebilirim?

Teşekkürler.
Kullanıcı avatarı
mussimsek
Admin
Mesajlar: 7588
Kayıt: 10 Haz 2003 12:26
Konum: İstanbul
İletişim:

Mesaj gönderen mussimsek »

Merhaba,

msdn'de bu konuda baya detaylı kaynaklar var. Ufak bir arama ile ilgili fonksiyonların adresini buldum.

http://msdn.microsoft.com/library/en-us ... t_9r77.asp

Kolay gelsin.
Sedat Atif
Üye
Mesajlar: 80
Kayıt: 18 Şub 2004 08:12
Konum: Fâni bir yerden
İletişim:

Mesaj gönderen Sedat Atif »

Teşekkürler, ancak bir sorun var, bunları nasıl kullanacağımı bilmiyorum. GetFontData'yı kullanmam gerek galiba, ama nasıl?
Kullanıcı avatarı
gkimirti
Admin
Mesajlar: 1956
Kayıt: 02 Eyl 2003 04:44
Konum: İstanbul

Mesaj gönderen gkimirti »

bu linkteki yardımcı prog.larla c deki funk.ları delphiye port edebilirsin
viewtopic.php?t=1682
ÜŞENME,ERTELEME,VAZGEÇME
Sedat Atif
Üye
Mesajlar: 80
Kayıt: 18 Şub 2004 08:12
Konum: Fâni bir yerden
İletişim:

Mesaj gönderen Sedat Atif »

Yapamadım... :cry:
Kullanıcı avatarı
gkimirti
Admin
Mesajlar: 1956
Kayıt: 02 Eyl 2003 04:44
Konum: İstanbul

Mesaj gönderen gkimirti »

delphi windows.pas icerisinde tanımlaması var

function GetFontData(DC: HDC; p2, p3: DWORD; p4: Pointer; p5: DWORD): DWORD; stdcall;

kullanımını msdn den okuyup bulman gerekiyor
ufak bir arama yaptım pek saglıklı bir sey bulamadım
hatta elemanın teki ttf i en korkunc fileformat diye nitelemis:(
ÜŞENME,ERTELEME,VAZGEÇME
Kullanıcı avatarı
mussimsek
Admin
Mesajlar: 7588
Kayıt: 10 Haz 2003 12:26
Konum: İstanbul
İletişim:

Mesaj gönderen mussimsek »

Merhaba,

evet ben de aaştırdım kolay bir yolu yok maalesef :( Msdn'de bilgileri ve fonksiyonları iyice incelemeniz lazım.

Kolay gelsin.
Sedat Atif
Üye
Mesajlar: 80
Kayıt: 18 Şub 2004 08:12
Konum: Fâni bir yerden
İletişim:

Mesaj gönderen Sedat Atif »

GetFontData
The GetFontData function retrieves font metric data for a TrueType font.

DWORD GetFontData(
HDC hdc, // handle to DC
DWORD dwTable, // metric table name
DWORD dwOffset, // offset into table
LPVOID lpvBuffer, // buffer for returned data
DWORD cbData // length of data
);

Bir de anlasam... Delphi dışı aramalar bile yaptım, herkes "GetFontData'yı kullanıyorum" falan diyor ama, nasıl kullanılıyor anlamıyorum...

:cry: :cry: :cry:
Sedat Atif
Üye
Mesajlar: 80
Kayıt: 18 Şub 2004 08:12
Konum: Fâni bir yerden
İletişim:

Mesaj gönderen Sedat Atif »

"Back in 1994 I wrote a DLL in C that was used to create TrueType font
files. From this experience I can tell you that .TTF is the most
horrible file format I have seen. Avoid messing with the format at all
costs."

:mrgreen:
Sedat Atif
Üye
Mesajlar: 80
Kayıt: 18 Şub 2004 08:12
Konum: Fâni bir yerden
İletişim:

Mesaj gönderen Sedat Atif »

Microsoft TTF ile ilgili bazı bilgiler vermiş.

name - Naming Table
The naming table allows multilingual strings to be associated with the TrueType font file. These strings can represent copyright notices, font names, family names, style names, and so on. To keep this table short, the font manufacturer may wish to make a limited set of entries in some small set of languages; later, the font can be “localized” and the strings translated or added. Other parts of the TrueType font file that require these strings can then refer to them simply by their index number. Clients that need a particular string can look it up by its platform ID, character encoding ID, language ID and name ID. Note that some platforms may require single byte character strings, while others may require double byte strings.
The Naming Table is organized as follows:

Type Description
USHORT Format selector (=0).
USHORT Number of NameRecords that follow n.
USHORT Offset to start of string storage (from start of table).
n NameRecords The NameRecords.
(Variable) Storage for the actual string data.
Each NameRecord looks like this:

Type Description
USHORT Platform ID.
USHORT Platform-specific encoding ID.
USHORT Language ID.
USHORT Name ID.
USHORT String length (in bytes).
USHORT String offset from start of storage area (in bytes).
Following are the descriptions of the four kinds of ID. Note that the specific values listed here are the only ones that are predefined; new ones may be added by registry with Apple Developer Technical Support. Similar to the character encoding table, the NameRecords is sorted by platform ID, then platform-specific ID, then language ID, and then by name ID.
(...)

Name ID’s
Code Meaning
0 Copyright notice.
1 Font Family name
2 Font Subfamily name; for purposes of definition, this is assumed to address style (italic, oblique) and weight (light, bold, black, etc.) only. A font with no particular differences in weight or style (e.g. medium weight, not italic and fsSelection bit 6 set) should have the string “Regular” stored in this position.
3 Unique font identifier
4 Full font name; this should simply be a combination of strings 1 and 2. Exception: if string 2 is “Regular,” then use only string 1. This is the font name that Windows will expose to users.
5 Version string. In n.nn format.
6 Postscript name for the font.
7 Trademark; this is used to save any trademark notice/information for this font. Such information should be based on legal advice. This is distinctly separate from the copyright.
Note that while both Apple and Microsoft support the same set of name strings, the interpretations may be somewhat different. But since name strings are stored by platform, encoding and language (placing separate strings in for both Apple and MS platforms), this should not present a problem.

The key information for this table for MS fonts relates to the use of strings 1, 2 and 4. Some examples:
Helvetica Narrow Oblique 1 = Helvetica Narrow
2 = Oblique
4 = Helvetica Narrow Oblique
Helvetica Narrow 1 = Helvetica Narrow
2 = Regular
4 = Helvetica Narrow
Helvetica Narrow Light Italic 1 = Helvetica Narrow
2 = Light Italic
4 = Helvetica Narrow Light Italic
Note that OS/2 and Windows both require that all name strings be defined in Unicode. Thus all ‘name’ table strings for platform ID = 3 (Microsoft) will require two bytes per character. See the chapter, “Character Sets,” for a list of the current Unicode character codes supported by Microsoft. Macintosh fonts require single byte strings.
Examples of how these strings might be defined:
0 The copyright string from the font vendor.
© Copyright the Monotype Corporation plc, 1990
1 The name the user sees.
Times New Roman
2 The name of the style.
Bold
3 A unique identifier that applications can store to identify the font being used.
Monotype: Times New Roman Bold:1990
4 The complete, hopefully unique, human readable name of the font. This name is used by Windows.
Times New Roman Bold
5 Release and version information from the font vendor.
June 1, 1990; 1.00, initial release
6 The name the font will be known by on a PostScript printer.
TimesNewRoman-Bold
7 Trademark string,
Times New Roman is a registered trademark of the Monotype Corporation.
Kullanıcı avatarı
mrmarman
Üye
Mesajlar: 4740
Kayıt: 09 Ara 2003 08:13
Konum: İstanbul
İletişim:

Mesaj gönderen mrmarman »

Selam...

- Eğer font özelliklerini öğrenmek sizin için çok önemliyse, önerim binary erişimle (blockread veya filestream) okumayı deneyin...

- AVI header okumak için OpenDML AVI Manual'i bir kaç defa okumak zorunda kalmıştım... Kabul ediyorum kolay bişi değil ama elinizde bir sürü font örneği olduğuna göre header yapısı hakkında çalışma yapılabilir, bu konuda deneyim edinebilirsiniz...

- Sizin için TTF header'ine şöyle bir baktım... Biraz çalışılırsa çözülür diye düşünüyorum... Boş vaktimde ayrıca bakıcam...
Resim
Resim ....Resim
Sedat Atif
Üye
Mesajlar: 80
Kayıt: 18 Şub 2004 08:12
Konum: Fâni bir yerden
İletişim:

Mesaj gönderen Sedat Atif »

Teşekkürler. Font dosyalarını hex editor ile açıp anlamaya çalıştım ama karmaşık geldi bana. Bir dosyada bilgiler font dosyasının başındayken bir dosyada sonunda mesela. Zaten binary erişimden de pek anlamıyorum.

GetFontData'nın nasıl kullanılacağını anlasam sorun azalacaktı ama... Bir tek şunu biliyorum, aradığım bilgiler "name" isimli tabloda saklı.

Internette de GetFontData'yı nasıl kullanacağını soran ve kullandığını söyleyenlere rastladım, ancak somut bir örnek bulamadım. Bunun dışında, ki o da farklı birşey yapıyor:

unit unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
FontDialog1: TFontDialog;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
procedure FontDialog1Apply(Sender: TObject; Wnd: HWND);
private
{ private declarations }
public
{ public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

function GetFontDataStr(DC: HDC; TblName: String): String;
var
TblNum: DWord;
Len: Integer;
begin
Result := '';
if TblName ='' then begin
TblNum := 0;
end else begin
if Length(TblName) <> 4 then exit;
Move(TblName[1], TblNum, 4);
end;
Len := GetFontData(DC, TblNum, 0, nil, 0);
if Len <= 0 then exit;
SetLength(Result, Len);
GetFontData(DC, TblNum, 0, PChar(Result), Len);
end;

function HasEuroSymbol(DC: HDC): Boolean;
begin
Result := Pos(#4'Euro', GetFontDataStr(DC, 'post')) > 0;
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
FontDialog1.Execute;

end;

procedure TForm1.FontDialog1Apply(Sender: TObject; Wnd: HWND);
begin
Font := FontDialog1.Font;
if HasEuroSymbol(Canvas.Handle) then
Label1.Caption := Font.Name + ' has a ''#128''-Zeichen'
else
Label1.Caption := Font.Name + ' does not have a euro-character';

end;

end.
Kullanıcı avatarı
mrmarman
Üye
Mesajlar: 4740
Kayıt: 09 Ara 2003 08:13
Konum: İstanbul
İletişim:

Mesaj gönderen mrmarman »

Selam...

- Bana etüd için referans olması açısından bir soru sorucam...

- Hex editör ile baktığınızda bir fontun bilgileri sonda, diğerinde başta demiştiniz ya, bu iki fontun isimlerini varsa download linklerini verir misiniz... Merak ettiğimden bir inceleyip sebebini araştırmak istedim...

- Belki header içinde bu pozisyonları bildiren adresler mevcuttur da baştan o posizyona seek ile atlayıp standart yöntemler belirleyip okutma şansımız olabilir...
Resim
Resim ....Resim
Sedat Atif
Üye
Mesajlar: 80
Kayıt: 18 Şub 2004 08:12
Konum: Fâni bir yerden
İletişim:

Mesaj gönderen Sedat Atif »

En son bunu bulabildim :cry:

/*
* An example TrueType font file name parsing program.
*
* Copyright 1992 Microsoft Corporation.
*
* Although this example code is parsing the 'name' table of
* a TrueType font, it could be readily adapted to parse any
* other table. See the "sfnt.h" include file for the
* predefined structures for the other tables in a TrueType
* font. For example, the 'post' table is referenced by the
* "sfnt_PostScriptInfo" structure.
*
* This code could also be useful for applications which
* wish to directly parse a TrueType font under Windows.
* Since Windows 3.1 allows an application to gain access
* to the raw font file via the GetFontData() API, this
* example code may be useful.
*
*/

#define PC_OS

#include <stdio.h>
#include <fcntl.h>
#include <io.h>
#include <errno.h>
#include <dos.h>
#include "fscdefs.h"
#include "sfnt.h"

void DumpNameTable (char *);

main(int argc, char **argv)
{
struct find_t FileInfo;

if (argc < 2) {
printf("usage: ttfname *.ttf\n");
exit(-1);
}

_dos_findfirst( argv[1], _A_NORMAL, &FileInfo );
do
DumpNameTable( FileInfo.name );
while ( !_dos_findnext( &FileInfo ) );
}


// find and seek to the naming table
void DumpNameTable (char * pszFile)
{
unsigned i;
char namebuf[255];
int fp;
unsigned short numNames;
long curseek;
unsigned cTables;
sfnt_OffsetTable OffsetTable;
sfnt_DirectoryEntry Table;
sfnt_NamingTable NamingTable;
sfnt_NameRecord NameRecord;

if ((fp = open (pszFile, O_RDONLY | O_BINARY)) == -1)
return;

/* First off, read the initial directory header on the TTF. We're only
* interested in the "numOffsets" variable to tell us how many tables
* are present in this file.
*
* Remember to always convert from Motorola format (Big Endian to
* Little Endian).
*/
read (fp, &OffsetTable, sizeof (OffsetTable) - sizeof (sfnt_DirectoryEntry));
cTables = (int) SWAPW (OffsetTable.numOffsets);

for ( i = 0; i < cTables && i < 40; i++)
{
if ((read (fp, &Table, sizeof (Table))) != sizeof(Table)) {
printf("Read failed on table #%d\n", i);
exit(-1);
}
if (Table.tag == tag_NamingTable) /* defined in sfnt_en.h */
{
/* Now that we've found the entry for the name table, seek to that
* position in the file and read in the initial header for this
* particular table. See "True Type Font Files" for information
* on this record layout.
*/
lseek (fp, SWAPL (Table.offset), SEEK_SET);
read (fp, &NamingTable, sizeof (NamingTable));
numNames = SWAPW(NamingTable.count);
while (numNames--) {
read (fp, &NameRecord, sizeof (NameRecord));
curseek = tell(fp);

/* Undefine this next section if you'd like a little bit more info
* during the parsing of this particular name table.
*/
#ifdef SPAM
printf("(%ld) platform=%u, specific=%u, lang=%x, name=%u (%u, %u)\n", curseek,
SWAPW(NameRecord.platformID),
SWAPW(NameRecord.specificID),
SWAPW(NameRecord.languageID),
SWAPW(NameRecord.nameID),
SWAPW(NameRecord.length),
SWAPW(NameRecord.offset));
#endif
if (SWAPW(NameRecord.platformID) == 1 &&
SWAPW(NameRecord.nameID) == 4) {
lseek (fp, SWAPW (NameRecord.offset) +
SWAPW(NamingTable.stringOffset) +
SWAPL(Table.offset), SEEK_SET);
read (fp, &namebuf, SWAPW(NameRecord.length));
namebuf[SWAPW(NameRecord.length)] = '\0';
printf("%s: FullFontName = %s\n", pszFile, namebuf);
lseek (fp, curseek, SEEK_SET);
}
}
goto cleanup;
}

}
printf("%s: ** No name table found **\n", pszFile);

cleanup:
close (fp);
return;
}
Cevapla