Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overlapping text (possible fix found) #26

Closed
Splatypus opened this issue Feb 23, 2021 · 21 comments
Closed

Overlapping text (possible fix found) #26

Splatypus opened this issue Feb 23, 2021 · 21 comments

Comments

@Splatypus
Copy link

using windows 10/photoshop CC2018. All fonts are installed and using a fresh pull and fresh template download. Running the script results in a lot of overlap in text boxes. This seems to happen using both normal and boxtopper cards.
image
image
image

@archangel519
Copy link

archangel519 commented Feb 23, 2021

@Splatypus
I had the same issue when I was trying to proxy Keruga, the Macrosage. It appears that if there is too much text for the text area, there are scaling issues in proxy.jsx around line 730. I have Adobe Photoshop CC 2019. I got my issue "fixed" by removing and adding these lines in proxy.jsx around line 730 (remove the minus lines and add the plus line):

-  var layerHeight = textboxRef.bounds[3] - textboxRef.bounds[1] - tolerance.as("cm");
-  var scaled = scaleTextToFitBox(rulesTextLayer, layerHeight);
+  var scaled = scaleTextToFitBox(rulesTextLayer, getRealTextLayerDimensions(textboxRef).height);

It seems that the layerHeight value is not being correctly calculated by using the bounds, so I just used the rastering and measuring method found in the getRealTextLayerDimensions function.

See if this helps out. I also made some tweaks to the scaleTextToFitBox function from excessFunctions.jsx file while I was testing fixes, but not sure if they were impactful or not. Try this and see if that helps. If you still have issues, I can give you my excessFunctions.jsx changes to see if those do the trick.

@Splatypus
Copy link
Author

Splatypus commented Feb 23, 2021

@archangel519 thanks for the help! You're right in that it seems to be an issue in the scaleTextToFitBox function. Unfortunately, the change on line 730 looks like it gets me the same results. What kind of changes did you make to escessFunctions?

@Splatypus
Copy link
Author

I seem to have fixed the issue by commenting out the entire

if(flavourIndex > 0) {

block at formatText.jsx line 940 to line 971.
Not entirely sure what this is for. The comment says "Adjust line break spacing if there's a line break in the flavour text" (same as the next if block). With this section removed, it seems to work as it should, even on any cards with line breaks in the flavour text.

@Splatypus Splatypus changed the title Overlapping text Overlapping text (possible fix found) Feb 23, 2021
@archangel519
Copy link

Sure, Here is my excessFunctions.jsx updates, beginning around line 26.

// Resize text to fit text box
function scaleTextToFitBox(textLayer, referenceHeight) {
  // Step down font size until text fits within the text box
  startingFontSize = textLayer.textItem.size;
  stepSize = .5;

  var fontSize = startingFontSize;
  var leadSize = fontSize * 1.2;

  var scaled = false;
  var inputWidth = new UnitValue(textLayer.textItem.width, "px");
  var number = textLayer.textItem.height;
  var inputHeight = new UnitValue(2 * (number), "px");

  while (referenceHeight < getRealTextLayerDimensions(textLayer).height) {
    scaled = true;

    // lower font size by 1
    fontSize = fontSize - stepSize;
    textLayer.textItem.size = new UnitValue(fontSize, "px");
    
  }

  return scaled;
}

I think the reason your change fixed your issue is because you are removing the flavor text from the text box, which makes the text not be too big for the text area. The changes I did in the function above basically hard sets the leadSize to 1.2x of the fontSize and does not try to do the previous math. The leadSize was what was causing issues for me if I remember correctly. It's been a few weeks since I had this issue and I'm not sure if my solution is the most elegant way to address this. :)
Your milage may vary.

@ndepaola
Copy link
Collaborator

what you guys are seeing with text layers is being caused by two things:

  1. at the start of the year, I updated all of my templates to consistently include the print bleed edge, and have the correct physical dimensions. This means that all of my template's font sizes dropped to starting at 9.18 pt, rather than the 60-something they started at before when I didn't properly account for physical card size. The font size fitter algorithm is currently (as in the version on the repo) set up to step down in 1pt increments.
  2. Photoshop has a known bug where if you transform a text layer - for example, reducing its size to half so the font size drops from 20pt to 10pt - any scripting code will think the font size is 20pt, even though it's clearly 10pt in the photoshop document. The only way to fix this that I'm aware of is to delete the text layer and recreate it.

So currently the repo is pretty broken and I apologise for that. I've been rebuilding all of my templates from scratch to make some tweaks to them (fixing bevels, drop shadows, textures, tweaking a few other things), and these new versions have text layers that have been regenerated to fix this issue. Additionally, I've modified my code to step down in 0.1pt increments and fix a slew of other unitvalue related issues I found. (e.g. the part where leadsize was set to 2x fontsize)

However I'm currently flat out with work and don't have much spare time so work on these templates is on hold atm. My plan was to release all of the new templates and update this repo all at once when the templates are done - I've made good progress on my templates but still have quite a few more to rebuild.

To be honest I wasn't sure that anyone other than myself really used this repo so that's why I haven't prioritised fixing the text layers on my current templates and pushing out a patch earlier haha

re: the purpose of the if (flavourIndex > 0) line and subsequent function call, the text formatter works by:

  1. inserting the specified oracle and flavour text into the layer, then formatting it. When it's formatting the text layer, if the card has flavour text, it'll increase the vertical spacing between rules text and flavour text a bit to match how real cards look (currently broken due to font size issues),
  2. stepping down the font size until the text fits inside the textbox (also currently broken),
  3. rasterising the layer and centering it vertically in the textbox,
  4. if the card is a creature card, it'll make sure the rules text doesn't overlap with the PT box.

@Splatypus
Copy link
Author

I know it's probably not enough for the work involved, but if it helps I can drop you a $100 donation with the release of the new working templates/code. This tool is fantastic.

@ndepaola
Copy link
Collaborator

holy moly!! you definitely don't have to but that'd be enormously appreciated <3 I'll let you know when I have more to share with regards to my new templates. thank you so much for the kind words!

@hunz-dev
Copy link

hunz-dev commented Jul 7, 2021

Just wanted to drop a comment that I've hit this same issue too when I updated my templates (accidentally overrode the old ones and had to update the repo to work with the new templates). I'd love to help you out @ndepaola if you need, I've been using a fork of your repo for over a year now and am thankful for what you've done to this point!!

Also thank you @Splatypus for the tip on commenting out that block, that did the trick for me too!

@ndepaola
Copy link
Collaborator

ndepaola commented Jul 7, 2021

this issue has been up for a while so I thought I should share an update as to my progress towards resolving it.

This year I've been working on redrawing all of my templates from scratch and I'm almost finished - just need to do the dfc/mdfc planeswalker templates for front/back and normal/extended variants. As soon as they're done I'll publish all of my new templates (which I think are significantly better quality than my old ones, check out images on my gdrive for a comparison as I have a mix of old and new there) and push my code changes that work with the new templates.

I'm also interested in spending some time after the new templates go live on improving the code quality of this repo, as a lot of it is shockingly bad and I've learned a lot since first creating it - that shouldn't entail any functional changes though

@ndepaola
Copy link
Collaborator

could you guys try pulling the latest changes and seeing if the updated scripts work w/ the new templates (available on my gdrive)? this should be resolved now

@hunz-dev
Copy link

hunz-dev commented Aug 1, 2021

Opening the new normal.psd in CS6 gave me this prompt:

image

I chose to Keep Layers and overwrote the existing file and ran the scripts, and it looks real close!

image

I'm thinking something may have been lost when I ran that conversion, but I don't think I can get around that.

@ndepaola which version of PS do you use?

@ndepaola
Copy link
Collaborator

ndepaola commented Aug 1, 2021

huh, very weird - i'm using CC 2018, but i used to use CS5 and i thought i was being mindful of backwards compatibility. i'll check it out (i think i still have CS5 installed) and see if it's a simple fix. looks like the script didn't read the size of the textbox reference layer properly so it didn't scale down the text at all, but it did rasterise and centre-justify the text relative to the reference.
also feel free to try pulling the refactor branch and see if that fixes the issue for you - i'm not sure why it would but maybe worth a shot!

@hunz-dev
Copy link

hunz-dev commented Aug 3, 2021

I'll try finding another version of PS to test with, on the refactor branch it looks like I have the same issue plus the mana cost is offset 😬

image

@ndepaola
Copy link
Collaborator

ndepaola commented Aug 5, 2021

hmm, this must have regressed while i was cutting down auto-generated code from format_text - frustrating that i can't recreate the issue locally! format_text on the refactor branch is now resetting the layer's justification to what it was pre-formatting as a final step - when you get a sec could you try pulling the latest changes and see if that fixes it?

re: text not scaling down - the code that drives this sits in scale_text_to_fit_reference in text_layers.jsx, you could try inserting some debugging alerts (like alert(reference_height) on line 41) - it must be something with it not measuring the bounds of the reference layer correctly.

@hunz-dev
Copy link

hunz-dev commented Aug 8, 2021

I pulled 71f8f4c1 and it still renders the same as my last reply unfortunately.

I added a couple print statements and noticed that one of the variables is NaN:

// Reduce the reference height by 64 pixels to avoid text landing on the top/bottom bevels
var reference_height = reference_dimensions.height - new UnitValue(64, "px");
alert(reference_height);  // NaN
alert(reference_dimensions.height);  // 1.04... in
alert(compute_text_layer_dimensions(layer).height);  // 1.17... in

I have no experience with PS scripting so not sure if it was a data type or conversion issue. I'd be happy to jump on a Discord call or something for a debug session if you're interested!

@ndepaola
Copy link
Collaborator

ndepaola commented Aug 9, 2021

i managed to recreate the issue by setting my default units in Photoshop to inches (from pixels) - will post an update when i resolve the bug (don't have much time to work on it atm)

@hunz-dev
Copy link

That fixed it for me, thanks for the tip! Wondering if you should bother fixing it or just include an instruction to set default units to pixels.

image

I'll try playing around with the mana cost again to see if I can get it back to normal for me.

@hunz-dev
Copy link

I extended the execute() function with some custom logic to force justify which seemed to do the trick, I tried it in a few places but this was the one that worked.

image

templates.jsx -- line 367:

    execute: function () {
        return_value = this.super();
        var mana_cost = app.activeDocument.layers.getByName(LayerNames.TEXT_AND_ICONS).layers.getByName(LayerNames.MANA_COST);
        mana_cost.textItem.justification = Justification.RIGHT;
        return return_value;
    }

@ndepaola
Copy link
Collaborator

i thought i'd fixed the justification issue (in format_text.jsx), but rereading my code now i must've been half asleep when i wrote it bc it was obviously wrong. also finally had time to play around with UnitValue maths with different photoshop settings and converting everything to pixels before doing any maths/comparisons seems to work. fixes for those two just went up, could you try pulling latest changes and testing again? appreciate your help with this!!

@hunz-dev
Copy link

Looks phenomenal, even fixed the mana cost overlap in the previous one!

image

My pleasure helping out, it's the least I could do for all your hard work on this repo. ❤️

@ndepaola
Copy link
Collaborator

excellent!! i'll merge in that branch and leave this issue open for a bit longer in case anyone else in this thread is still having issues <3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants