php-font-lib icon indicating copy to clipboard operation
php-font-lib copied to clipboard

Get specific platform name entry

Open guidoferreyra opened this issue 5 years ago • 5 comments

Hi! I want to get the string associated with the Mac Entry id 2?

I tried different things but I dont get it.

getNameTableString() only returns Win entries?

guidoferreyra avatar Oct 09 '19 17:10 guidoferreyra

If you're still interested in this can you clarify what you want to retrieve?

bsweeney avatar Jan 11 '24 04:01 bsweeney

I just discovered this problem. By modifying it and adding other key information, I got what I needed.

I've modified these functions below so that you can get a more specific message and use your own judgment to suit your needs. This change improves flexibility, but also increases the complexity for users.

In addition, I also tried to support automatic encoding detection under mac fonts.

https://github.com/lslqtz/php-font-lib/commit/cc1a5a813887bcd8d265cc63c48bde8f2225c863

The most common combinations tend to be the following:

Mac (1,0,0,1) Font Family: FZLanTingYuan-DB-GBK
Mac (1,0,0,2) Font Subfamily: Regular
Mac (1,0,0,3) Unique Identifier: Founder:FZLanTingYuan-DB-GBK	Regular
Mac (1,0,0,4) Full Name: FZLanTingYuan-DB-GBK
Mac (1,0,0,5) Version: 1.00
Mac (1,0,0,6) PostScript Name: FZLANTY_ZHONGK--GBK1-0

Microsoft (3,1,1033,1) Font Family: FZLanTingYuan-DB-GBK
Microsoft (3,1,1033,2) Font Subfamily: Regular
Microsoft (3,1,1033,3) Unique Identifier: Founder:FZLanTingYuan-DB-GBK	Regular
Microsoft (3,1,1033,4) Full Name: FZLanTingYuan-DB-GBK
Microsoft (3,1,1033,5) Version: 1.00

2052: Language ID
Microsoft (3,1,1033,6) PostScript Name: FZLANTY_ZHONGK--GBK1-0
Microsoft (3,1,2052,1) Font Family: 方正兰亭圆_GBK_中
Microsoft (3,1,2052,2) Font Subfamily: Regular
Microsoft (3,1,2052,3) Unique Identifier: Founder:方正兰亭圆_GBK_中	Regular
Microsoft (3,1,2052,4) Full Name: 方正兰亭圆_GBK_中

(BTW: https://github.com/ConradIrwin/font is a good program. Its info tool can list the raw data in detail, which is helpful for your debugging.)

Specifically:

  ["3,1,1033,4"]=>
  object(FontLib\Table\Type\nameRecord)#43 (9) {
    ["f":protected]=>
    NULL
    ["platformID"]=>
    int(3)
    ["platformSpecificID"]=>
    int(1)
    ["languageID"]=>
    int(1033)
    ["nameID"]=>
    int(4)
    ["length"]=>
    int(40)
    ["offset"]=>
    int(675)
    ["string"]=>
    string(20) "FZLanTingYuan-DB-GBK"
    ["stringRaw"]=>
    string(40) "FZLanTingYuan-DB-GBK"
  }

If I don't modify it, it just discards/overwrites this information.

function getFontCopyright($platformID, $platformSpecificID, $languageID)
function getFontName($platformID, $platformSpecificID, $languageID)
function getFontSubfamily($platformID, $platformSpecificID, $languageID)
function getFontSubfamilyID($platformID, $platformSpecificID, $languageID)
function getFontFullName($platformID, $platformSpecificID, $languageID)
function getFontVersion($platformID, $platformSpecificID, $languageID)
function getFontPostscriptName($platformID, $platformSpecificID, $languageID)

Usage like this:

				if ($font->getFontName(3,1,2052) !== null) {
					$fontsInfoArr[] = [$font->getFontName(3,1,2052), $font->getFontFullName(3,1,2052), $font->getFontPostscriptName(3,1,2052), $font->getFontSubfamily(3,1,2052)];
				}
				if ($font->getFontName(3,1,1033) !== null) {
					$fontsInfoArr[] = [$font->getFontName(3,1,1033), $font->getFontFullName(3,1,1033), $font->getFontPostscriptName(3,1,1033), $font->getFontSubfamily(3,1,1033)];
				}

lslqtz avatar Feb 11 '24 16:02 lslqtz

@lslqtz feel free to submit a PR with those changes. Happy to review and include in a future release.

bsweeney avatar Feb 11 '24 20:02 bsweeney

@lslqtz feel free to submit a PR with those changes. Happy to review and include in a future release.

I'm using a very simple modification, so I'm not sure I can guarantee its backwards compatibility, especially since I don't fully analyze and understand its replacement behavior. But this modification did solve my problem, so I posted these usages and cases in issues that may be similar.

Since these new parameters are required in my modification, it may become a breaking change.

(Another problem is that I only modified the TrueType function, which may lead to inconsistent usage between different font type)

lslqtz avatar Feb 12 '24 09:02 lslqtz

Thank you for the follow up. I'll review your changes and see how we can adapt them.

Also, if you have any sample fonts for testing that would be great.

bsweeney avatar Feb 12 '24 13:02 bsweeney