Jump to content

128A barcode


hoover

Recommended Posts

Hi

 

I made a 128A barcode rule. Feel free to test and use it.

Paste this in BuildingBlocks.js (on Mac you find the file in Library/Application Support/Printable/FusionPro on PC in don't know)

[Edit from Dan Korn: Please don't modify the BuildingBlocks.js file! See: http://forums.printable.com/showpost.php?p=9999&postcount=7]

  FusionPro.Builtins.Barcode["Make128ABarcode"] =
{
 description: "Make128ABarcode",
 description_GERMAN: "Make128ABarcode",
 description_FRENCH: "Make128ABarcode",
 description_SPANISH: "Make128ABarcode",
 description_ITALIAN: "Make128ABarcode",
 syntax: "Make128ABarcode(str)"
}

Paste this in Builtins.js (on Mac you find the file in Library/Application Support/Printable/FusionPro on PC in don't know)

[Edit from Dan Korn: Please don't modify the Builtins.js file! See: http://forums.printable.com/showpost.php?p=9999&postcount=7]

After:

//////////////////////////////////////////////////////////////////////////////////////////////

//********************************************************************************************

//

// Barcode Functions

//

//////////////////////////////////////////////////////////////////////////////////////////////

 

//==================================================================
//Make128BarcodeA(str): Returns the Code128 barcode using CodeA
//                           
//                  IN: str - the  code 
//                   
//
//                RETVAL: the encoded value with the calculated check digit 
//
//------------------------------------------------------------------
function Make128BarcodeBaseA(str, isCodeA)
{
   var StartCodeChecksum = 103;
   var EndCode = 206;    
   var StartCode = 203; 
   var strAscCharStringMinus32 = "";
   var strAscCharStringMinus32Weight = "";
   var CheckSum = 0;

   if (!isCodeA)
   {
         StartCodeChecksum++;
     StartCode++;
   }

   for(var index = 0;  index < str.length   ; index++ )
   {
       if(str.charAt(index) == 32)
       {
           CheckSum += 194; //(194 * (index+1) );                    
       }
       else
       {    
           var a = Asc(str.charAt(index));
           if (a < 135) 
             a -= 32;
           else
             if (a > 134) 
             a -= 100;
           else
             a -= 00;

           CheckSum += (a * (index+1) );                    
       }
   }

     CheckSum += StartCodeChecksum;    
   CheckSum = CheckSum % 103;
   var CharToPrintForCheckSum;
   if (CheckSum == 0)
      CharToPrintForCheckSum = 194;
   else if (CheckSum < 95)
        CharToPrintForCheckSum = CheckSum + 32;
      else if (CheckSum > 94)
        CharToPrintForCheckSum = CheckSum + 100;
   else
       CharToPrintForCheckSum = CheckSum + 00 ;

   str = ReplaceSubstring(str, " ", String.fromCharCode(194));
   //String.fromCharCode(CharCode)


   if ((CharToPrintForCheckSum == 38)||(CharToPrintForCheckSum == 60)||(CharToPrintForCheckSum == 62)||(CharToPrintForCheckSum == 34))
var Make128BarcodeBaseA_Result =String.fromCharCode(StartCode) + str+NormalizeEntities(String.fromCharCode(CharToPrintForCheckSum))+String.fromCharCode(EndCode);
else
var Make128BarcodeBaseA_Result =String.fromCharCode(StartCode) + str+String.fromCharCode(CharToPrintForCheckSum)+String.fromCharCode(EndCode);


 for (var i in Make128BarcodeBaseA_Result)
 {
   if (Make128BarcodeBaseA_Result.charCodeAt(i) == 0)

     ThrowError("Make128ABarcode" , TranslateAndBuildMessage("Internal error in {0} barcode generation.", "128A"));
 }

 return Make128BarcodeBaseA_Result;
}

//

Make128BarcodeBaseA.builtin = true;
Make128BarcodeA.builtin = true;



function Make128ABarcode(str)
{
 return Make128BarcodeBaseA(str, true);
}
Make128ABarcode.builtin = true;


   //------------------------------------------------------------------
function MakeEAN128BarcodeA(str)
{
 var i, c0, c1;
 var barcodestr;

 barcodestr = "";

 for (i=0;i<str.length;i++)
 {
   if (!isdigitA(str[i]))
   {
     if (str[i] == '(')
        barcodestr +=  Chr(202); // if it is open paren, put out fnc1
     // if it is some other character, just skip it - such as close paren.
   }
   else
   {
     c0 = str.charAt(i);
     if (i+1 < str.length)
       c1 = str.charAt(i+1);
     else
       c1 = "0";
     while ((i+1 < str.length) && !isdigitA(c1[0]))
     {
       i++;
       c1 = str.charAt(i+1);
     }

     //c1 = (i+1 < str.length && isdigitA(str[i+1])) ? str.charAt(i+1) : '0';
     var doubleVal = parseInt(c0) * 10 + parseInt(c1) + 32;
     i++;
     if (doubleVal > 126)
       doubleVal += 68;
     barcodestr += Chr(doubleVal);
   }
 }

 return Make128BarcodeBaseA(barcodestr, false);
}
MakeEAN128BarcodeA.builtin = true;

function isdigitA(str)
{ 
 return (str[0] <= "9" && str[0] >= "0");
}
isdigitA.builtin = true;

function Make128BarcodeA(str)
{
 var startAcode = true;
 var inCodeC = false;
 var i,j, digitcount;
 var barcodestr="";
 var switchToA = Chr(200);
 var switchToC = Chr(199);
 var doubleVal;

 if (str.length >= 3 && isdigitA(str[0]) && isdigitA(str[1]) && isdigitA(str[2]))
 {
   digitcount=0;
   for (j=0;j<str.length && isdigitA(str[j]);j++) // see if there are an odd or even # of digits in this run. If odd, start in code A.
   {
     digitcount++;
   }
   if (digitcount % 2 == 0) // an even  # of digits
   {
     startAcode = false;
     inCodeC = true;
   }
 }

 for (i=0;i<str.length;i++)
 {
   if (inCodeC)
   {
     if (!isdigitA(str[i])) // see if we've reached the end
     {
       inCodeC=false;
       i--; // redo this character
       barcodestr += switchToA;
     }
     else
     {
       doubleVal = parseInt(str.charAt(i)) * 10 + parseInt(str.charAt(i+1)) + 32;
       i++;
       if (doubleVal > 126)
         doubleVal += 68;
       barcodestr += Chr(doubleVal);
     }
   }
   else  // we're in code A
   {
     if (str.length - i >= 3 && isdigitA(str[i]) && isdigitA(str[i+1]) && isdigitA(str[i+2]))
     {
       inCodeC=true;
       digitcount = 0;
       for (j=i;j<str.length;j++) // see if there are an odd or even # of digits in this run. If odd, use up first character.
       {
         if (!isdigitA(str[j]))              
           j = str.length+1;              
         else
           digitcount++;
       }
       if (digitcount % 2 == 1) // an odd # of digits
         barcodestr += str[i];
       else            
         i--; // redo this character
       barcodestr += switchToC;
     }
     else
     {
       barcodestr += str[i];
     }
   }
 }

 return Make128BarcodeBaseA(barcodestr, startAcode);

....

Link to comment
Share on other sites

Then create with notepad or texteditor an xml file and call it something like 128ABarcodeRule.xml

paste the following code there:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<template_rule name="128 A Barcode Rule" version="1.0" taggedtext="true" type="text">
<rulename language="en-US">128 A Barcode Rule</rulename>
<rulename language="de">Barcode-Regel 128 A</rulename>
<rulename language="fr">Règle Codes-barres de code 128 A</rulename>
<rulename language="es">Regla de código de barras 128 A</rulename>
<rulename language="it">Regola codice a barre 128 A</rulename>
<Comment language="en-US">Apply the Make128ABarcode rule to your text field(s).</Comment>
<Comment language="de">Die Make128ABarcode-Regel auf Ihr(e) Textfeld(er) anwenden.</Comment>
<Comment language="fr">Appliquer la règle Make128ABarcode à votre ou vos champs texte.</Comment>
<Comment language="es">Aplique la regla Make128ABarcode a sus campos de texto.</Comment>
<Comment language="it">Applica regola Make128ABarcode a campi di testo.</Comment>
<Description language="en-US">Choose the field(s) for your barcode.</Description>
<Description language="de">Wählen Sie das bzw. die Felder für Ihren Barcode.</Description>
<Description language="fr">Choisissez le ou les champs pour votre code-barres.</Description>
<Description language="es">Elija los campos correspondientes a su código de barras.</Description>
<Description language="it">Scegliere i campi per il codice a barre.</Description>

<fieldlist>
 <field type="FIELDLIST" required="true">
   <fieldname>Var1</fieldname>
   <prompt language="en-US">Choose a field:</prompt>
   <prompt language="de">Wählen Sie ein Feld:</prompt>
   <prompt language="fr">Choisissez un champ :</prompt>
   <prompt language="es">Elija un campo:</prompt>
   <prompt language="it">Scegliere un campo:</prompt>
   <value></value>
 </field>
 <field type="FIELDLIST">
   <fieldname>Var2</fieldname>
   <prompt language="en-US">Choose another field (optional):</prompt>
   <prompt language="de">Wählen Sie ein weiteres Feld (optional):</prompt>
   <prompt language="fr">Choisissez un autre champ (facultatif) :</prompt>
   <prompt language="es">Elija otro campo (opcional):</prompt>
   <prompt language="it">Scegliere un altro campo (opzionale):</prompt>
   <value></value>
 </field>
 <field type="FIELDLIST">
   <fieldname>Var3</fieldname>
   <prompt language="en-US">Choose another field (optional):</prompt>
   <prompt language="de">Wählen Sie ein weiteres Feld (optional):</prompt>
   <prompt language="fr">Choisissez un autre champ (facultatif) :</prompt>
   <prompt language="es">Elija otro campo (opcional):</prompt>
   <prompt language="it">Scegliere un altro campo (opzionale):</prompt>
   <value></value>
 </field>
 <field type="FIELDLIST">
   <fieldname>Var4</fieldname>
   <prompt language="en-US">Choose another field (optional):</prompt>
   <prompt language="de">Wählen Sie ein weiteres Feld (optional):</prompt>
   <prompt language="fr">Choisissez un autre champ (facultatif) :</prompt>
   <prompt language="es">Elija otro campo (opcional):</prompt>
   <prompt language="it">Scegliere un altro campo (opzionale):</prompt>
   <value></value>
 </field>
 <field type="FIELDLIST">
   <fieldname>Var5</fieldname>
   <prompt language="en-US">Choose another field (optional):</prompt>
   <prompt language="de">Wählen Sie ein weiteres Feld (optional):</prompt>
   <prompt language="fr">Choisissez un autre champ (facultatif) :</prompt>
   <prompt language="es">Elija otro campo (opcional):</prompt>
   <prompt language="it">Scegliere un altro campo (opzionale):</prompt>
   <value></value>
 </field>

 <field type="FONTLIST" required="true">
   <fieldname>Var6</fieldname>
   <prompt language="en-US">Pick a font:</prompt>
   <prompt language="de">Wählen Sie eine Schriftart:</prompt>
   <prompt language="fr">Choisissez une police :</prompt>
   <prompt language="es">Seleccione una fuente:</prompt>
   <prompt language="it">Scegliere un tipo di carattere:</prompt>
   <value>IDAutomationC128L</value>
 </field>

</fieldlist>
<code>

retstr = Field(Var1);
final_data = "";

if (Var2 != "")
       retstr += Field(Var2);

if (Var3 != "")
       retstr += Field(Var3);

if (Var4 != "")
       retstr += Field(Var4);

if (Var5 != "")
       retstr += Field(Var5);


final_data = '<span><f name="' + Var6 + '">' +  NormalizeEntities(Make128ABarcode(retstr)) + '</span>';

if (retstr == "")
   return retstr;
else
   return final_data;

</code>
</template_rule>

And so you have the same function as the 128B barcode (use the font IDautomationC128)

I've tested 5000 records for errors and at the moment everything works perfect.

Hope this is useful for someone.

Greetz,

Hoover

Link to comment
Share on other sites

  • 11 months later...
  • 4 weeks later...
Paste this in Builtins.js (on Mac you find the file in Library/Application Support/Printable/FusionPro on PC in don't know)

I have to strongly discourage editing of the Builtins.js or BuildingBlocks.js files. If you uninstall and re-install FusionPro, your changes will be lost. Also, if you collect up the job for composition on another machine, either in FP Desktop, or if you upload it to FP Direct or an FP Server system such as MarcomCentral, the other computer doing the composition won't have your changes, and calling the function won't work.

 

If you need to add functions specific to your machine, I recommend creating your own .js file and placing it in the Plug-ins folder, under the install folder on Windows (typically "C:\Program Files\Printable\FusionPro\Plug-ins") or the Application Support folder on Mac ("/Library/Application Support/Printable/FusionPro/Plug-ins"). You can even add syntax and descriptions in multiple languages to the functions, and they will appear in the Building Blocks dialog. The functions will still not be collected up for remote compositions, however.

 

If you want the rule to be preserved with the rest of the job, you can place it in the JavaScript Globals.

 

But your best bet, if you're creating an XML Template rule anyway, is to simply place the logic inside the XML. This way, it will be automatically added to any job which uses the XML Template rule.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...