Skip to content

Instantly share code, notes, and snippets.

@ImperatorJulius
Created November 2, 2020 08:25
Show Gist options
  • Save ImperatorJulius/795eb3cd8c49b960fb75ee4ba00e3bff to your computer and use it in GitHub Desktop.
Save ImperatorJulius/795eb3cd8c49b960fb75ee4ba00e3bff to your computer and use it in GitHub Desktop.
mtg autoproxy justification
function insertName(textAndIcons, cardName, cardnameLayerName, isIxalan) {
var docRef = app.activeDocument;
// var textAndIcons = docRef.layers.getByName("Text and Icons");
var cardnameLayer = textAndIcons.layers.getByName(cardnameLayerName);
cardnameLayer.textItem.contents = cardName;
if (!isIxalan && textAndIcons.layers.getByName("Mana Cost").visible) {
// Scale down the name to fit in case it's too long
var symbolLeftBound = textAndIcons.layers.getByName("Mana Cost").bounds[0].as("px");
var typelineRightBound = cardnameLayer.bounds[2].as("px");
var nameFontSize = cardnameLayer.textItem.size;
while (typelineRightBound > symbolLeftBound - 16) { // minimum 16 px gap
cardnameLayer.textItem.size = new UnitValue(nameFontSize - 1, "px");
nameFontSize = nameFontSize - 1;
typelineRightBound = cardnameLayer.bounds[2].as("px");
}
}
docRef.activeLayer = cardnameLayer;
docRef.activeLayer.name = "Card Name";
docRef.activeLayer.textItem.justification = Justification.RIGHT; // Force justification
}
function insertTypeline(textAndIcons, typeLine, typelineLayerName, isIxalan) {
var docRef = app.activeDocument;
// textAndIcons = docRef.layers.getByName("Text and Icons");
var typelineLayer = textAndIcons.layers.getByName(typelineLayerName);
typelineLayer.textItem.contents = typeLine;
if (!isIxalan) {
// Scale down the typeline to fit in case it's too long
var symbolLeftBound = textAndIcons.layers.getByName("Expansion Symbol").bounds[0].as("px");
var typelineRightBound = typelineLayer.bounds[2].as("px");
var typelineFontSize = typelineLayer.textItem.size;
while (typelineRightBound > symbolLeftBound - 16) { // minimum 16 px gap
typelineLayer.textItem.size = new UnitValue(typelineFontSize - 1, "px");
typelineFontSize = typelineFontSize - 1;
typelineRightBound = typelineLayer.bounds[2].as("px");
}
}
docRef.activeLayer = typelineLayer;
docRef.activeLayer.name = "Typeline";
docRef.activeLayer.textItem.justification = Justification.RIGHT; // Force justification
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment