diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b73bb55 --- /dev/null +++ b/.gitignore @@ -0,0 +1,13 @@ +# build artifacts +sd-changer.sketchplugin + +# npm +node_modules +.npm +npm-debug.log + +# mac +.DS_Store + +# WebStorm +.idea \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..18819bb --- /dev/null +++ b/README.md @@ -0,0 +1,18 @@ +# SD Changer + +SD Changer는 한국어로 언어 설정 된 iOS 화면을 더 쉽게 디자인 하도록, Apple SD Gothic Neo 폰트를 일괄로 SF Pro Display로 바꿔주는 Sketch plugin 입니다. + +## Keys + +- Menu `Plugins` › `SD Changer` +- Shortcut `shift` `option` `command` `D` + +## Features + +선택된 레이어나 그룹, 아트보드 안의 Apple SD Gothic Neo 폰트가 적용된 텍스트 레이어를 찾아, SF Pro Display로 변환합니다. 아무것도 선택되지 않은 상태에서 작동하면 현재 Page의 모든 텍스트 레이어를 대상으로 합니다. + +## Install + +- [플러그인 파일](https://github.com/yeun/sd-changer/releases/latest)을 다운로드 받습니다. +- 압축을 풉니다. +- .sketchplugin 파일을 더블클릭해 설치합니다. \ No newline at end of file diff --git a/assets/icon.png b/assets/icon.png new file mode 100644 index 0000000..d19a20d Binary files /dev/null and b/assets/icon.png differ diff --git a/package.json b/package.json new file mode 100644 index 0000000..7d0f00f --- /dev/null +++ b/package.json @@ -0,0 +1,26 @@ +{ + "name": "sd-changer", + "engines": { + "sketch": ">=3.0" + }, + "skpm": { + "name": "sd-changer", + "manifest": "src/manifest.json", + "main": "sd-changer.sketchplugin", + "assets": [ + "assets/**/*" + ] + }, + "scripts": { + "build": "skpm-build", + "watch": "skpm-build --watch", + "start": "skpm-build --watch --run", + "postinstall": "npm run build && skpm-link" + }, + "devDependencies": { + "@skpm/builder": "^0.5.2" + }, + "author": "jeongheeyeun ", + "repository": "https://github.com/yeun/sd-changer", + "description": "Converts Apple SD Gothic Neo font to SF Pro Display" +} diff --git a/src/manifest.json b/src/manifest.json new file mode 100755 index 0000000..05f0298 --- /dev/null +++ b/src/manifest.json @@ -0,0 +1,23 @@ +{ + "name" : "SD Chagner", + "description" : "Converts Apple SD Gothic Neo font to SF Pro Display", + "author" : "Heeyeun Jeong", + "authorEmail" : "heeyeun.design@gmail.com", + "compatibleVersion": 3, + "bundleVersion": 1, + "icon": "icon.png", + "commands": [ + { + "name": "SD Chagner", + "identifier": "sd-changer", + "script": "./sd-changer.js", + "shortcut" : "shift option cmd d" + } + ], + "menu": { + "isRoot": true, + "items": [ + "sd-changer" + ] + } +} \ No newline at end of file diff --git a/src/sd-changer.js b/src/sd-changer.js new file mode 100755 index 0000000..5dfe1f1 --- /dev/null +++ b/src/sd-changer.js @@ -0,0 +1,75 @@ +export default function(context) { + const doc = context.document + const page = doc.currentPage() + const selection = context.selection + + function changeFont(layer) { + var fontName = layer.fontPostscriptName() + var fontWeight = fontName.split("-")[1] + var fontWeights = { + "Thin": "Light", + "UltraLight": "Light", + "Light": "Light", + "Regular": "Regular", + "Medium": "Medium", + "SemiBold": "Semibold", + "Bold": "Bold", + "ExtraBold": "Heavy", + "Heavy": "Heavy" + }; + var weight = fontWeights[fontWeight] + + if (fontName.hasPrefix("AppleSDGothicNeo")) { + layer.select_byExpandingSelection(true, true) + layer.fontPostscriptName = "SFProDisplay-" + weight + return true + } + return false + } + + function selectLayersByType(selectedlayer) { + var count = 0 + + if (selectedlayer.containsLayers() && selectedlayer.class() != "MSShapeGroup") { + var loopChildrens = selectedlayer.children().objectEnumerator() + var layer + while (layer = loopChildrens.nextObject()) { + if (layer.class() == MSTextLayer) { + var changed = changeFont(layer) + if (changed) count ++ + } + } + } else if (selectedlayer.containsLayers() == false && selectedlayer.class() == "MSTextLayer") { + var changed = changeFont(selectedlayer) + if (changed) count ++ + } + return count + } + + // Fix Sketch 45 + if (page.deselectAllLayers) { + page.deselectAllLayers() + } else { + page.changeSelectionBySelectingLayers(nil) + } + + var totalCount = 0 + + if (selection.count() == 0) { + var count = selectLayersByType(page) + totalCount = count + } else { + var loop = selection.objectEnumerator() + var layer + while (layer = loop.nextObject()) { + var count = selectLayersByType(layer) + totalCount += count + } + } + + if (totalCount == 0) { + doc.showMessage("바꿀 레이어가 없습니다 😲") + } else { + doc.showMessage(totalCount + " 개의 산돌 고딕 레이어를 바꿨습니다 😎") + } +}