Skip to content

Commit

Permalink
feat: Add support for auto-height text (introduced in XD 34)
Browse files Browse the repository at this point in the history
  • Loading branch information
pklaschka committed Mar 4, 2021
1 parent ca3995d commit 5115695
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 33 deletions.
2 changes: 1 addition & 1 deletion dist/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"version": "1.3.0",
"host": {
"app": "XD",
"minVersion": "24.0"
"minVersion": "34.0"
},
"icons": [
{ "width": 24, "height": 24, "path": "icons/icon@1x.png" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,40 +21,70 @@ const lang = require('xd-localization-helper');
* @returns {void}
*/
module.exports = function fillSelectionWithPlaceholderText(options) {
const selection = require('scenegraph').selection;
const selection = require('scenegraph').selection;

debugHelper.log('Lorem ipsum with options ', options);
debugHelper.log('Lorem ipsum with options ', options);

// Parse termination string:
let terminationString =
options.terminationString === 'n/a' ? '' : options.terminationString;
// Parse termination string:
let terminationString =
options.terminationString === 'n/a' ? '' : options.terminationString;

try {
for (let sceneNode of selection.items) {
if (sceneNode instanceof Rectangle) {
applyToAreaText(replaceWithText(sceneNode), options, terminationString);
} else if (sceneNode instanceof Text && sceneNode.areaBox) {
applyToAreaText(sceneNode, options, terminationString);
} else if (sceneNode instanceof Text) {
applyToPointText(sceneNode, options, terminationString);
} else {
debugHelper.log('Node', sceneNode, 'is not a text layer.');
}
}
} catch (e) {
showErrorDialog(
lang.get('error.general.title'),
lang.get('error.general.description') + '<br>' + e.message
);
}
try {
for (let sceneNode of selection.items) {
if (sceneNode instanceof Rectangle) {
applyToAreaText(replaceWithText(sceneNode), options, terminationString);
} else if (
sceneNode instanceof Text &&
// @ts-ignore
sceneNode.layoutBox.type === Text.FIXED_HEIGHT
) {
applyToAreaText(sceneNode, options, terminationString);
} else if (
sceneNode instanceof Text &&
// @ts-ignore
sceneNode.layoutBox.type === Text.POINT
) {
applyToPointText(sceneNode, options, terminationString);
} else if (
sceneNode instanceof Text &&
// @ts-ignore
sceneNode.layoutBox.type === Text.AUTO_HEIGHT
) {
// Convert to fixed-height text with same dimensions, apply "normal" procedure, than convert back.

analytics
.verifyAcceptance({
pluginName: 'Lorem Ipsum',
privacyPolicyLink: 'https://xdplugins.pabloklaschka.de/privacy-policy',
color: '#2D4E64'
})
.then(() => {
analytics.send('lorem', options);
});
// @ts-ignore
sceneNode.layoutBox = {
width: sceneNode.localBounds.width,
height: sceneNode.localBounds.height,
// @ts-ignore
type: Text.FIXED_HEIGHT
};
applyToAreaText(sceneNode, options, terminationString);
// @ts-ignore
sceneNode.layoutBox = {
// @ts-ignore
type: Text.AUTO_HEIGHT,
width: sceneNode.localBounds.width
};
// applyToAutoHeightText(sceneNode, options, terminationString);
} else {
debugHelper.log('Node', sceneNode, 'is not a text layer.');
}
}
} catch (e) {
showErrorDialog(
lang.get('error.general.title'),
lang.get('error.general.description') + '<br>' + e.message
);
}

analytics
.verifyAcceptance({
pluginName: 'Lorem Ipsum',
privacyPolicyLink: 'https://xdplugins.pabloklaschka.de/privacy-policy',
color: '#2D4E64'
})
.then(() => {
analytics.send('lorem', options);
});
};

0 comments on commit 5115695

Please # to comment.