[GastForen Programme Print/Bildbearbeitung Adobe InDesign Skriptwerkstatt Fehlende Schriftzeichen filtern

  • Suche
  • Hilfe
  • Lesezeichen
  • Benutzerliste
Print/Bildbearbeitung - Photos, Layout, Design
Themen
Beiträge
Moderatoren
Letzter Beitrag

Fehlende Schriftzeichen filtern

fabiantheblind
Beiträge gesamt:

6. Dez 2010, 17:46
Beitrag # 1 von 6
Bewertung:
(2189 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Hello Leute,

kann mir jemand erklären wie ich fehlende Zeichen eines fonts filtern kann?
Ich habe folgenden Code der jedem Zeichen in einer Textkiste einen zufälligen Font zuweisst. Leider kommen dann natürlich auch fonts hinzu die das entsprechende Zeichen nicht besitzen. Wie kann ich das verhindern?

Grüsse
:F

Hier der Code:
Code
main(); 

function main(){
// setup some variables
var theDoc = app.activeDocument; // active doc
var thePage = theDoc.pages.item(0); // first page
var theTextFrame = thePage.textFrames.item(0);
for(var i = 0;i < theTextFrame.characters.length; i++){
var theValue = Math.floor(Math.random()*app.fonts.length-1);
theTextFrame.characters.item(i).appliedFont = app.fonts.item(theValue);
}
}

X

Fehlende Schriftzeichen filtern

Martin Fischer
  
Beiträge gesamt: 12783

6. Dez 2010, 18:11
Beitrag # 2 von 6
Beitrag ID: #459021
Bewertung:
(2179 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Hallo Fabian,

versuche die einzelnen Zeichen in Pfade umzuwandeln.

Dort, wo dies gelingt, ist das Zeichen darstellbar (im Font vorhanden).
Dort, wo dies misslingt, kann das Zeichen nicht dargestellt werden (nicht im Font vorhanden).


als Antwort auf: [#459018]

Fehlende Schriftzeichen filtern

fabiantheblind
Beiträge gesamt:

6. Dez 2010, 18:24
Beitrag # 3 von 6
Beitrag ID: #459025
Bewertung:
(2174 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
hm.
Das ist natürlich ne Möglichkeit aber dadurch wird ja der Text zerstört.
Also nicht nur Text -> Vectorform, sondern auch die Lesbarkeit von Worten.
Trotzdem danke.
Behalte ich im Hinterkopf.

:F


als Antwort auf: [#459021]

Fehlende Schriftzeichen filtern

Martin Fischer
  
Beiträge gesamt: 12783

6. Dez 2010, 18:34
Beitrag # 4 von 6
Beitrag ID: #459028
Bewertung:
(2168 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
> Das ist natürlich ne Möglichkeit aber dadurch wird ja der Text zerstört.

Freilich musst Du das temporär erledigen.

Entweder über undo() wieder zurücknehmen oder das Zeichen vorher in einen dafür eingerichteten temporären Textrahmen kopieren und dort experimentieren.

Mir ist keine andere Methode zur Prüfung, ob ein Zeichen im Font vorhanden ist, bekannt. Und ich glaube, den Hinweis auf diese Methode habe ich mal von Peter Kahrel bekommen.


Siehe etwa die Funktion try_char() in Peters Skript compose_cs_3.jsx.
Code
function try_char (uni, ch, diacr) 
{
var ip = app.selection[0];
var pos = ip_position (app.selection[0]);
try
{
// insert the character
ip.contents = uni;
// create outline
ip.paragraphs[0].characters[pos].createOutlines();
// if we got here it worked, so delete the outline
ip.paragraphs[0].characters[pos].remove();
// insert the character (again)
ip.contents = uni;
exit();
}
catch(_)
{
// couldn't create outline, so delete it
ip.paragraphs[0].characters[pos].remove();
// and create overstrike of ch and diacr
overstrike (stripdot (ch), diacr)
}
}



als Antwort auf: [#459025]
(Dieser Beitrag wurde von Martin Fischer am 6. Dez 2010, 18:35 geändert)

Fehlende Schriftzeichen filtern

fabiantheblind
Beiträge gesamt:

6. Dez 2010, 20:45
Beitrag # 5 von 6
Beitrag ID: #459036
Bewertung:
(2139 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Cool. Das funktioniert.
Man könnte jetzt in der Funktion try_char() im catch Block einfach ein Liste von wirklich funktonierend Fonts haben um die "Zufälligkeit" zu simulieren.

Oder gibt es die Möglichkeit ihn jetzt an den Anfang zurückzuschicken und wieder einen Font auszuwählen?
Also sowas wie
Code
returnTo(line 23) 

Da habe ich ja nen bisschen Angst vor. Nacher ist mein Rechner für immer am Fonts ausprobieren ;)

Tausend Dank erstmal
:F

Code
main(); 
// this is the function
function main(){
// setup some variables
var theDoc = app.activeDocument; // active doc
var thePage = theDoc.pages.item(0); // first page
var theTextFrame = thePage.textFrames.item(0); // the one Textframe that is there

// now we can loop thru the Text
for(var i = 0;i < theTextFrame.characters.length; i++){
//make a random value for the font
var theValue = Math.floor(Math.random()*app.fonts.length-1);
// store the character
var theChar = theTextFrame.characters.item(i);
//apply the font
theChar.appliedFont = app.fonts.item(theValue);
//check with try_char() if the character can be displayed with the random font
try_char(theChar);
}

}

function try_char (theChar)
{

try
{
// save the character
var storage = theChar.contents;
// create outline
theChar.createOutlines();
// if we got here it worked, so delete the outline
// if not it will cause an error
theChar.remove();
// insert the character (again)
theChar.contents = storage;
}
catch(e)
{
// couldn't create outline, apply a basic font.
// this could hold an array of working fonts
//to simulate the randomness twinkle twinkle
theChar.appliedFont = "Times";
}
}



als Antwort auf: [#459028]

Fehlende Schriftzeichen filtern

fabiantheblind
Beiträge gesamt:

6. Dez 2010, 21:51
Beitrag # 6 von 6
Beitrag ID: #459046
Bewertung:
(2122 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Zitat Da habe ich ja nen bisschen Angst vor. Nacher ist mein Rechner für immer am Fonts ausprobieren

UPDATE:
Ich habe mich überwunden und drei mal die function try_char() benutzt. So lande ich bei 3 falschen von 2363 Zeichen.
Also ca. 0,12%
Da kann man fast mit Comic Sans leben.

Grüsse und danke nochmal
:F

Hier der komplette Code

Code
// fontify.jsx 
// written by fabiantheblind
// function try_char (theChar)
// with some help from Martin Fischer
// based on Peter Kahrel's compose_cs3.jsx http://www.kahrel.plus.com/indesign/compose_cs3.jsx

// warning this takes a long time.

var theDialoge = app.dialogs.add({name:"WARNING!", canCancel:true});
with(theDialoge){
with(dialogColumns.add()){
staticTexts.add({staticLabel:"This takes a very long time!"});
staticTexts.add({staticLabel:"Abort running process with \"ESC\""});
staticTexts.add({staticLabel:"or resize the page in function buildDoc()"});

}
}
if(theDialoge.show() == true){
theDialoge.destroy();

main();
}

function main(){
// setup some variables
var theDoc = buildDoc();
var thePage = theDoc.pages.item(0); // first page

var theTextFrame = thePage.textFrames.add({
geometricBounds:getBounds(theDoc,thePage)

});
theTextFrame.textFramePreferences.textColumnCount = thePage.marginPreferences.columnCount;
theTextFrame.textFramePreferences.textColumnGutter = thePage.marginPreferences.columnGutter;

theTextFrame.contents = TextFrameContents.placeholderText;

// now we can loop thru the Text
for(var i = 0;i < theTextFrame.characters.length; i++){
var theValue = Math.floor(Math.random()*app.fonts.length-1);
// store the character in a variable
var theChar = theTextFrame.characters.item(i);
// apply the font
theChar.appliedFont = app.fonts.item(theValue);

try_char(theChar);
}

}

function try_char (theChar)
{

try
{
// save the character
var storage = theChar.contents;
// create outline
theChar.createOutlines();
// if we got here it worked, so delete the outline
theChar.remove();
// insert the character (again)
theChar.contents = storage;
}
catch(e)
{
// couldn't create outline, apply a basic font.
var theValue = Math.floor(Math.random()*app.fonts.length-1);
theChar.appliedFont = app.fonts.item(theValue);
try_char_again(theChar);
}
}

function try_char_again (theChar)
{

try
{
// save the character
var storage = theChar.contents;
// create outline
theChar.createOutlines();
// if we got here it worked, so delete the outline
theChar.remove();
// insert the character (again)
theChar.contents = storage;
}
catch(e)
{
// couldn't create outline, apply a basic font.
var theValue = Math.floor(Math.random()*app.fonts.length-1);

theChar.appliedFont = app.fonts.item(theValue);
try_char_forTheLastTime(theChar);
}
}
function try_char_forTheLastTime (theChar)
{

try
{
// save the character
var storage = theChar.contents;
// create outline
theChar.createOutlines();
// if we got here it worked, so delete the outline
theChar.remove();
// insert the character (again)
theChar.contents = storage;
}
catch(e)
{
// couldn't create outline, apply a basic font.
theChar.appliedFont = "Times";
// now we have about 0,12% non working characters so we can live with Times
}
}


function buildDoc(){
var theDoc = app.documents.add()
with (theDoc.documentPreferences) {
pageWidth = "210mm";
pageHeight = "210mm";
//BleedBox settings
documentBleedBottomOffset = "3mm";
documentBleedTopOffset = "3mm";
documentBleedInsideOrLeftOffset = "3mm";
documentBleedOutsideOrRightOffset = "3mm";
}
// have to look up why the size is declared in 2 ways
with (theDoc.viewPreferences) {
pageWidth = "210mm";
pageHeight = "210mm";
// to make shure we have the right positions and units
horizontalMeasurementUnits = MeasurementUnits.MILLIMETERS;
verticalMeasurementUnits = MeasurementUnits.MILLIMETERS;
rulerOrigin = RulerOrigin.pageOrigin;

}

with(theDoc.masterSpreads.item(0).pages.item(0).marginPreferences){
left = "13mm";
top = "23mm";
right = "13mm";
bottom = "23mm";
columnCount = 3;
columnGutter = "4mm";
}
with(theDoc.masterSpreads.item(0).pages.item(1).marginPreferences){
left = "13mm";
top = "23mm";
right = "13mm";
bottom = "23mm";
columnCount = 3;
columnGutter = "4mm";
}


return theDoc;
}

function getBounds(myDocument, myPage){
var myPageWidth = myDocument.documentPreferences.pageWidth;
var myPageHeight = myDocument.documentPreferences.pageHeight
if(myPage.side == PageSideOptions.leftHand){
var myX2 = myPage.marginPreferences.left;
var myX1 = myPage.marginPreferences.right;
}
else{
var myX1 = myPage.marginPreferences.left;
var myX2 = myPage.marginPreferences.right;
}
var myY1 = myPage.marginPreferences.top;
var myX2 = myPageWidth - myX2;
var myY2 = myPageHeight - myPage.marginPreferences.bottom;
return [myY1, myX1, myY2, myX2];
}



als Antwort auf: [#459036]
X