Quantcast
Channel: Planet DTP@jp
Viewing all articles
Browse latest Browse all 4835

FORCE: [CSS]フォントの各名称とCSS【その2】

$
0
0

その1は
http://force4u.cocolog-nifty.com/skywalker/2016/02/csscss-838a.html


繰り返しになりますが
CSSのフォント指定はあくまでも『ファミリ名』ですが
フォントを指定する場合に有効なのが

PostScript名
フル・フォント名
ファミリー名+ウェイト名
フォント・ファミリー名 を指定出来ると、各ブラウザで表示出来るわけです。

ポイントは
ローカライズ名ではなく英語で指定するのがセオリー

英語でフォントの各種名称を取得する場合
有効なのが
表示言語の一時変更での
フォントブックでの取得が簡単でしょう


Website_image00280211_165241


サンプルはヒラギノですので
スタイル部分がW3になっていますが
ウェイトを取得出来る事もあります。

それ以外の方法だと
mdls
スポットライトコマンドで取得出来ます。

/usr/bin/mdls -name com_apple_ats_names
/usr/bin/mdls -name com_apple_ats_name_full
/usr/bin/mdls -name com_apple_ats_name_fond
/usr/bin/mdls -name com_apple_ats_name_family
/usr/bin/mdls -name com_apple_ats_name_postscript
/usr/bin/mdls -name com_apple_ats_name_style

スクリプトにするとこんな感じ

Website_image00280211_172417_2

(*
com_apple_ats_name_family.scpt

Uniform Type Identifiers Reference
public.truetype-collection-fontを指定していますが
異なるファミリーが同封されている場合は
全てのファミリは取得出来ません。
フォントブックを英語モードに切り替えて利用する事をお勧めします

*)
-----ファインダー呼び出し
tellapplication"Finder"
activate
---ファイルを選択 TTF TTC OTF PS1のみ選べます Font Suitcase等は選べません
setobjResultto¬
choose filedefault location (path tofonts folderfromuser domain) ¬
of type¬
{"public.truetype-ttf-font", "public.truetype-collection-font", "public.opentype-font", "com.apple.truetype-datafork-suitcase-font", "com.adobe.postscript-lwfn​-font"} invisiblestrue¬
withmultiple selections allowedwithoutshowing package contents

endtell


settheLogFileto"" astext


----繰り返しのはじまり
repeatwithobjFilesinobjResult
----ファインダー処理
tellapplication"Finder"
----取得したファイルのエリアスを取得
settheFileIAliastoobjFilesasalias
----ファイル名を取得
settheFontNameto (nameof (info forobjFiles) aslist) astext
----フォントがあるディレクトリを取得
settheFileDirto (containerofobjFiles) astext
----UNIXパスにしておきます
settheUnixFilePathto (POSIX pathoftheFileIAlias) astext
endtell
-----mdlsのコマンドを実行して格納
settheMdlsResulttodo shell script"/usr/bin/mdls -name com_apple_ats_name_postscript \"" & theUnixFilePath& "\""

-----区切り文字を改行に設定
setAppleScript's text item delimitersto {"\r"}
-----改行毎のリストとして格納
settheResultListto (everytext itemoftheMdlsResult) aslist
-----区切り文字を戻す
setAppleScript's text item delimitersto {""}
-----何行あるか?(データ件数)を数える
setnumListLineto (countoftheResultList) asnumber

settheLineDatato (item 2 oftheResultList) astext
settheResultTexttomydoReplace(theLineData, "\t", "") astext
settheResultTexttomydoReplace(theResultText, "\"", "") astext
settheResultTexttomydoReplace(theResultText, ",", "") astext
settheResultTextPostscripttomydoReplace(theResultText, " ", "") astext


settheMdlsResultto"" astext
-----mdlsのコマンドを実行して格納
settheMdlsResulttodo shell script"/usr/bin/mdls -name com_apple_ats_name_family \"" & theUnixFilePath& "\""
-----区切り文字を改行に設定
setAppleScript's text item delimitersto {"\r"}
-----改行毎のリストとして格納
settheResultListto (everytext itemoftheMdlsResult) aslist
-----区切り文字を戻す
setAppleScript's text item delimitersto {""}
-----何行あるか?(データ件数)を数える
setnumListLineto (countoftheResultList) asnumber

settheLineDatato (item 2 oftheResultList) astext
settheResultTexttomydoReplace(theLineData, "\t", "") astext
settheResultTexttomydoReplace(theResultText, "\"", "") astext
settheResultTexttomydoReplace(theResultText, ",", "") astext
settheResultTextFamilytomydoReplace(theResultText, " ", "") astext

settheMdlsResultto"" astext

-----mdlsのコマンドを実行して格納
settheMdlsResulttodo shell script"/usr/bin/mdls -name com_apple_ats_name_full \"" & theUnixFilePath& "\""
-----区切り文字を改行に設定
setAppleScript's text item delimitersto {"\r"}
-----改行毎のリストとして格納
settheResultListto (everytext itemoftheMdlsResult) aslist
-----区切り文字を戻す
setAppleScript's text item delimitersto {""}
-----何行あるか?(データ件数)を数える
setnumListLineto (countoftheResultList) asnumber

settheLineDatato (item 2 oftheResultList) astext
settheResultTexttomydoReplace(theLineData, "\t", "") astext
settheResultTexttomydoReplace(theResultText, "\"", "") astext
settheResultTexttomydoReplace(theResultText, ",", "") astext
settheResultTextFulltomydoReplace(theResultText, " ", "") astext


-----mdlsのコマンドを実行して格納
settheMdlsResulttodo shell script"/usr/bin/mdls -name com_apple_ats_name_style \"" & theUnixFilePath& "\""
-----区切り文字を改行に設定
setAppleScript's text item delimitersto {"\r"}
-----改行毎のリストとして格納
settheResultListto (everytext itemoftheMdlsResult) aslist
-----区切り文字を戻す
setAppleScript's text item delimitersto {""}
-----何行あるか?(データ件数)を数える
setnumListLineto (countoftheResultList) asnumber

settheLineDatato (item 2 oftheResultList) astext
settheResultTexttomydoReplace(theLineData, "\t", "") astext
settheResultTexttomydoReplace(theResultText, "\"", "") astext
settheResultTexttomydoReplace(theResultText, ",", "") astext
settheResultTextStyletomydoReplace(theResultText, " ", "") astext



settheLogFiletotheLogFile& "\r\rcom_apple_ats_name_postscript\r" & theResultTextPostscript& "\r\rcom_apple_ats_name_family\r" & theResultTextFamily& "\r\rcom_apple_ats_name_full\r" & theResultTextFull& "\r\rcom_apple_ats_name_style\r" & theResultTextStyle& "\r\r" astext

logtheLogFile

endrepeat



returntheLogFile













---------文字の置き換えサブルーチン
todoReplace(theText, orgStr, newStr)
setoldDelimtoAppleScript's text item delimiters
setAppleScript's text item delimiterstoorgStr
settmpListtoeverytext itemoftheText
setAppleScript's text item delimiterstonewStr
settmpStrtotmpListastext
setAppleScript's text item delimiterstooldDelim
returntmpStr
enddoReplace


「apple_ats_name_family.scpt.zip」をダウンロード



Viewing all articles
Browse latest Browse all 4835

Trending Articles