Estoy creando un PDF multilingüe en Illustrator con variables y me gustaría usar cuadros de área de texto de una sola línea para controlar el tipo. Sin embargo, en algunos idiomas, el texto será muy largo. ¿Puedo establecer un tamaño de fuente específico para el área de texto y luego, si el texto excede su cuadro, hacer que se deforme, reduzca o reduzca el seguimiento para que quepa? No quiero que se ajuste a una nueva línea.
Estoy usando ExtendScript para intentar hacer esto en muchos pasos y sigo teniendo limitaciones. Para obtener el ancho del texto real, lo estoy convirtiendo en tipo de punto convertAreaObjectToPointObject()
que funciona cuando el texto es más pequeño que su cuadro. Si se desborda, el método siempre se recorta como su equivalente de GUI en Tipo > Convertir a tipo de punto.
Extender el ancho del tipo de área mediante programación antes de convertirlo en punto para evitar el recorte usando .width
estira el tipo en lugar de su cuadro contenedor. ¿Hay otro método que deba usar que simule agarrar el borde de expansión del tipo de área?
Usando los caracteres y líneas difíciles de manejar y los objetos de secuencias de comandos de párrafo, puede usar algún método para verificar si el texto del área está desbordado. Aquí en este script hay una función que lo resume.
function isOverset(textBox) {
if (textBox.lines.length > 0) {
if (textBox.lines[0].characters.length < textBox.characters.length) {
return true;
} else {
return false;
}
} else if (textBox.characters.length > 0) {
return true;
}
}
También escribí este artículo de LinkedIn sobre este tema para quien pueda encontrarlo útil.
Esto parece una solución muy fea, así que estoy ansioso por ver mejoras. Resulta que necesitaba configurar el width
de textPath
, no el textFrame
. También tuve muchos problemas desconocidos con la aplicación .convertPointObjectToAreaObject()
y su reverso a las variables como si estuvieran perdiendo la referencia.
function shrink_all_text_frames_to_fit (layer_name) {
var currentLayer = app.activeDocument.layers[layer_name];
for (var i = 1; i < currentLayer.textFrames.length; i++) {
currentLayer.textFrames[i].textRange.characterAttributes.horizontalScale = 100; // reset so the script can be run multiple times
while (check_text_overflow(currentLayer, i))
shrinkAndCheckSize(currentLayer, i);
}
}
function check_text_overflow(layer, frame_number) {
var save_box_fontsize = layer.textFrames[frame_number].textRange.characterAttributes.size;
var save_box_width = layer.textFrames[frame_number].width;
var save_box_height = layer.textFrames[frame_number].height;
var save_horizontal_scale = layer.textFrames[frame_number].textRange.characterAttributes.horizontalScale;
layer.textFrames[frame_number].textPath.width = 200; // Set high to avoid the next line clipping text
layer.textFrames[frame_number].convertAreaObjectToPointObject(); // Convert to point type to measure width
var text_width = layer.textFrames[frame_number].width;
layer.textFrames[frame_number].convertPointObjectToAreaObject(); // Convert back to area and restore size
layer.textFrames[frame_number].width = save_box_width;
layer.textFrames[frame_number].height = save_box_height;
layer.textFrames[frame_number].textRange.characterAttributes.horizontalScale = save_horizontal_scale;
layer.textFrames[frame_number].textRange.characterAttributes.size = save_box_fontsize;
return (text_width > save_box_width);
}
function shrinkAndCheckSize(layer, frame_number) {
layer.textFrames[frame_number].textRange.characterAttributes.horizontalScale -= 5;
}
shrink_all_text_frames_to_fit("Layer Name");
Lucent