Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit e520a71

Browse files
committed
- Support variable fonts.
- Do not export embedded fonts.
1 parent db65ca7 commit e520a71

14 files changed

+18373
-29
lines changed

gxdesignops.sketchplugin/Contents/Sketch/__see-result.js

+4,519-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gxdesignops.sketchplugin/Contents/Sketch/__see-result.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gxdesignops.sketchplugin/Contents/Sketch/__send-to-queue-file.js

+4,239-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gxdesignops.sketchplugin/Contents/Sketch/__send-to-queue-file.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gxdesignops.sketchplugin/Contents/Sketch/__send-to-queue-gx-sketch.js

+4,537-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gxdesignops.sketchplugin/Contents/Sketch/__send-to-queue-gx-sketch.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gxdesignops.sketchplugin/Contents/Sketch/__send-to-queue.js

+4,215-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gxdesignops.sketchplugin/Contents/Sketch/__send-to-queue.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gxdesignops.sketchplugin/Contents/Sketch/__set-queue-path.js

+755-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gxdesignops.sketchplugin/Contents/Sketch/manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"gxdesignops.set-queue-path"
3939
]
4040
},
41-
"version": "2.2.6",
41+
"version": "2.2.8",
4242
"description": "Sketch Plugin For GeneXus Design Ops Cycles",
4343
"name": "GxDesignOps",
4444
"identifier": "GxDesignOps",

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "gxdesignops",
33
"description": "Sketch Plugin For GeneXus Design Ops Cycles",
44
"repository": "https://github.com/genexuslabs/sketchdesignops.git",
5-
"version": "2.2.7",
5+
"version": "2.2.8",
66
"engines": {
77
"sketch": ">=49.0"
88
},

src/see-result.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import sketch from 'sketch';
22

33

44
import { spawnSync , execSync} from '@skpm/child_process';
5-
import { getFileAndQueueName, getQueuePath, copyFonts } from './utils';
6-
import { os } from '@skpm/os';
5+
import { getFileAndQueueName, getQueuePath } from './utils';
6+
77

88
var UI = require("sketch/ui");
99
var zip = require("jszip");

src/test.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// getJsonDocument(sketch.getSelectedDocument());
2+
// copyFonts(sketch.getSelectedDocument(), "/Users/gmilano/Documents/DesignSketchs/FontsCopiadas" )

src/utils.js

+98-16
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,48 @@ import Settings from 'sketch/settings';
33
import { spawnSync, execSync } from '@skpm/child_process';
44
import { SettingKeys } from './constants';
55

6+
export function getJsonDocument(doc) {
7+
var filePath = decodeURIComponent(doc.path);
8+
var fileName = decodeURIComponent(doc.path).replace(/^.*[\\\/]/, '').trim();
9+
var tmpFileDocumentName = `/var/tmp/${fileName}.json`;
10+
log("Reading Json Document:" + filePath);
11+
const unzipCmd = `unzip -p '${filePath}' document.json > '${tmpFileDocumentName}'`;
12+
log(unzipCmd);
13+
var exec = execSync(unzipCmd);
14+
if (exec) {
15+
var contents = readFile(`/var/tmp/${fileName}.json`);
16+
if (contents) {
17+
removeFile(tmpFileDocumentName);
18+
return JSON.parse(contents);
19+
}
20+
}
21+
return null;
22+
}
23+
24+
export function isFileExist(source) {
25+
const manager = NSFileManager.defaultManager()
26+
return manager.fileExistsAtPath(source)
27+
}
28+
29+
export function copyFile2(source, target) {
30+
const manager = NSFileManager.defaultManager()
31+
if( !manager.fileExistsAtPath(source)) throw new Error(`file not exist ${source}`)
32+
manager.copyItemAtPath_toPath_error(source, target, null)
33+
}
34+
35+
export function writeToFile(path, content) {
36+
const resultStr = NSString.stringWithFormat('%@', content)
37+
resultStr.writeToFile_atomically(path, true)
38+
}
39+
40+
export function removeFile(path) {
41+
const manager = NSFileManager.defaultManager()
42+
manager.removeItemAtPath_error(path, null)
43+
}
44+
45+
function readFile(path) {
46+
return NSString.stringWithContentsOfFile_encoding_error(path, NSUTF8StringEncoding, null);
47+
}
648

749
export function getFileAndQueueName(doc, queuePath) {
850
var branch = "";
@@ -87,6 +129,7 @@ export function copyFile(fromCopyFile, toCopyFile) {
87129
return false;
88130
}
89131
else {
132+
log("Copied !")
90133
return true;
91134
}
92135
}
@@ -137,16 +180,32 @@ var exportLayer = function (layer, path) {
137180

138181
var traverseFonts = function (layer, fonts) {
139182
if (layer.type == "Text" && layer.style.fontFamily != "Helvetica") {
140-
console.log(layer.style.fontFamily + "-" + layer.style.fontWeight);
141-
var fontName = NSFontManager.sharedFontManager().fontWithFamily_traits_weight_size(layer.style.fontFamily, 0, layer.style.fontWeight, layer.style.fontSize).fontName()
142-
var displayName = NSFontManager.sharedFontManager().fontWithFamily_traits_weight_size(layer.style.fontFamily, 0, layer.style.fontWeight, layer.style.fontSize).displayName()
143-
console.log("FONT NAME:" + fontName);
144-
console.log("Display NAME:" + displayName);
145-
var font = String(fontName);
146-
if (!fonts.includes(font)) {
147-
fonts.push(String(font));
183+
log(layer.style.fontFamily + "-" + layer.style.fontWeight);
184+
var fontManager = NSFontManager.sharedFontManager();
185+
if (!fontManager) {
186+
log("NSFontManager sharedFontManager NULL !!!");
187+
return;
188+
}
189+
if (layer.style.fontFamily && layer.style.fontWeight && layer.style.fontSize) {
190+
var nFont = fontManager.fontWithFamily_traits_weight_size(layer.style.fontFamily, 0, layer.style.fontWeight, layer.style.fontSize);
191+
if (nFont) {
192+
var fontName = nFont.fontName();
193+
log("FONT NAME:" + fontName);
194+
var font = String(fontName);
195+
if (!fonts.includes(font)) {
196+
fonts.push(String(font));
197+
}
198+
} else {
199+
// maybe its a reference to a Variable Font, just add the familyname
200+
log("Font not found !! : ");
201+
log(layer.style.fontFamily + "-" + layer.style.fontWeight + "-" + layer.style.fontSize);
202+
if (!fonts.includes(layer.style.fontFamily))
203+
fonts.push(layer.style.fontFamily);
204+
}
205+
}
206+
else {
207+
log("Something wrong with this font: " + layer.style.fontFamily + "-" + layer.style.fontWeight + "-" + layer.style.fontSize);
148208
}
149-
150209
}
151210
if (layer.layers) {
152211
layer.layers.forEach(l => {
@@ -176,7 +235,7 @@ function getPostcriptNames(path) {
176235
var retMetadata = execSync(fontNameCmd);
177236
if (retMetadata)
178237
return retMetadata.toString();
179-
} catch {}
238+
} catch { }
180239
return "";
181240
}
182241

@@ -214,17 +273,40 @@ export function copyFonts(doc, path) {
214273
}
215274
}
216275
}
217-
218-
219276
);
220277

221278
fonts.forEach(fontName => {
222-
if (mapping[fontName] != undefined) {
223-
var cmdCpy = `cp ${mapping[fontName].replace(/\s/g, '\\ ')} ${path}`
224-
console.log(cmdCpy);
225-
execSync(cmdCpy);
279+
if (mapping[fontName] != undefined) {
280+
var cmdCpy = `cp ${mapping[fontName].replace(/\s/g, '\\ ')} ${path}`
281+
console.log(cmdCpy);
282+
execSync(cmdCpy);
283+
}
284+
else {
285+
log("Looking in references for " + fontName)
286+
// we couldn't find in the traditional way, just unzip the document and see the font references
287+
var document = getJsonDocument(doc);
288+
if (document) {
289+
if (document.fontReferences) {
290+
for (var i in document.fontReferences) {
291+
if (document.fontReferences[i].fontData) {
292+
log("Font is embbeded");
293+
break;
294+
}
295+
if (String(document.fontReferences[i].fontFamilyName).localeCompare(fontName) == 0) {
296+
var cmdCpy = `cp ${"~/Library/Fonts/" + String(document.fontReferences[i].fontFileName).replace(/\s/g, '\\ ')} ${path}`
297+
try {
298+
if (execSync(cmdCpy)) {
299+
log("copied !");
300+
break;
301+
}
302+
}
303+
catch {}
304+
}
305+
}
226306
}
307+
}
227308
}
309+
}
228310
)
229311
}
230312

0 commit comments

Comments
 (0)