Last active
June 10, 2020 23:58
-
-
Save macneko-ayu/3d155ff68e55f33b0e41c3ccee1734ee to your computer and use it in GitHub Desktop.
Extendscript for creating font samples in Indesign
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// sample movie: https://user-images.githubusercontent.com/5406126/49324964-f631aa80-f57c-11e8-9199-0ab51231422c.gif | |
main(); | |
function main() { | |
// 関数定義 | |
function applyFontToStory(targetFont) { | |
for (var i = 0, txLen = doc.textFrames.length; i < txLen; i++) { | |
doc.textFrames[i].parentStory.appliedFont = targetFont; | |
} | |
} | |
function extractFontsFromName(wantToExtractFontName) { | |
var result = []; | |
if (undefined == wantToExtractFontName) { | |
return app.fonts; | |
} | |
var regexp = new RegExp(wantToExtractFontName, 'i'); | |
for (var i = 0, len = app.fonts.length; i < len; i++) { | |
var font = app.fonts[i]; | |
if (!isExpectFont(font)) { | |
continue; | |
} | |
try { | |
if (regexp.test(font.fullNameNative)) { | |
result.push(font); | |
} | |
} catch (e) { | |
if (regexp.test(font.fullName)) { | |
result.push(font); | |
} | |
} | |
} | |
return result.length > 0 ? result : undefined; | |
} | |
function exportPDFX4(pdfName) { | |
doc.exportFile(ExportFormat.pdfType, File(saveObj + '/' + pdfName + '.pdf'), false, '[PDF/X-4:2008 (日本)]'); | |
} | |
function exportJPEG(jpegName) { | |
doc.exportFile(ExportFormat.JPG, File(saveObj + '/' + jpegName + '.jpg'), false); | |
} | |
function isExpectFont(targetFont) { | |
try { | |
if (targetFont.fontType == FontTypes.BITMAP) { | |
return false; | |
} | |
if (targetFont.fontType == FontTypes.OCF) { | |
return false; | |
} | |
if (targetFont.fontType == FontTypes.TYPE_1) { | |
return false; | |
} | |
if (!targetFont.allowPDFEmbedding) { | |
return false; | |
} | |
} catch (e) { | |
return false; | |
} | |
return true; | |
} | |
// ここから処理開始 | |
var wantToExtractFontName = prompt('検索したいフォント名を入力してください', '', 'Font search'); | |
if (null == wantToExtractFontName) { | |
return; | |
} | |
var saveObj = Folder.selectDialog("PDFを保存するフォルダを選択してください"); | |
if (undefined == saveObj) { | |
return; | |
} | |
var preference = app.jpegExportPreferences; | |
preference.antiAlias = true; | |
preference.exportResolution = 72 * 4; | |
preference.jpegColorSpace = JpegColorSpaceEnum.RGB; | |
preference.jpegQuality = JPEGOptionsQuality.MAXIMUM; | |
var doc = app.activeDocument; | |
var extractedFonts = extractFontsFromName(wantToExtractFontName); | |
if (undefined == extractedFonts) { | |
alert('フォントが見つかりません'); | |
return; | |
} | |
for (var i = 0, len = extractedFonts.length; i < len; i++) { | |
applyFontToStory(extractedFonts[i]); | |
var fontName = ''; | |
try { | |
fontName = extractedFonts[i].fullNameNative; | |
} catch (e) { | |
fontName = extractedFonts[i].fullName; | |
} | |
exportPDFX4(fontName); | |
exportJPEG(fontName); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment