在仅支持ECMA3的Photoshop中检测文本层notdef字符的可行性问询
Great question! First, let me clear up a misconception I had earlier — those strange replacement symbols you see (like �) aren't actually mojibake (garbled text). JosefZ corrected me on this: they're .notdef glyphs, which Photoshop displays when the selected font doesn't have a glyph for the character you're trying to render.
To answer your core question: Yes, you can detect .notdef characters in a text layer even with Photoshop's ECMA3-only scripting limitations, though it requires some creative workarounds since direct glyph access isn't built into the scripting API here.
Let me start with the test script I used to validate this behavior:
var theLayer = activeDocument.activeLayer; if (theLayer.kind == "LayerKind.TEXT") { // theLayer.textItem.font = "ArialMT"; // Fails to render Japanese characters theLayer.textItem.font = "Meiryo"; // Renders correctly theLayer.textItem.contents = "グウェンステファニー"; }
Test Results:
- When using the Meiryo font (which supports Japanese characters), the text displays exactly as intended:
グウェンステファニー - Switching to Arial (which lacks Japanese glyphs), Photoshop replaces missing characters with
.notdefglyphs, showing up as:���������
Note: The � characters here are just a stand-in for the actual.notdefsymbols you'd see in Photoshop
Practical Detection Methods for ECMA3
Since ECMA3 doesn't include modern string utilities or direct glyph mapping tools, here are two reliable workarounds:
- Cross-font comparison: Render the same text content using a font that supports all characters in your string (like a comprehensive Unicode font) and the target font. If the visual output differs (or you check for bounding box inconsistencies), it indicates
.notdefglyphs are present. - Character code validation: For specific character ranges you're working with, temporarily switch the text layer to a font that supports those characters. If the layer's appearance changes, the original font was using
.notdeffor some characters.
Neither method is a perfect one-liner, but they're effective given the ECMA3 constraints in Photoshop.
内容的提问来源于stack exchange,提问作者Ghoul Fool

