• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Still after help with Barcode font issue, Please!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Still after help with Barcode font issue, Please!


  • Subject: Still after help with Barcode font issue, Please!
  • From: Brian Christmas <email@hidden>
  • Date: Sat, 27 Feb 2016 17:40:31 +1100

G’day scripters

I’m getting desperate. I’m still trying to use the Barcode 128 font from this site, and finding problems. I’ve spent 3 days trying everything I can think of. I’m now wondering if the .ttf font has something wrong with it, or is incompatible with Macs for some reason.

The similar barcode font from this second Barton site will NOT display in Text Edit, even though the font seems to work correctly in other Applications, after ignoring the displayed Ascii values, and using the Ascii values of the shown characters, which differ by a value of 28.

I’m posting in the two forums in the hope of getting an answer, but the mod 103 values in the first sites font does not display a barcode character all the time.

Any, any advice appreciated, especially if someone could check my code against the C# example at the end.

Regards

Santa

tell application "TextEdit"
activate
tell application "System Events" to tell process "TextEdit"
keystroke "n" using command down
end tell
end tell
set theText to "This is barcode 128. "
repeat with x from 1 to 10
set theText to (theText & " " & x as text)
set theModulusCharacter to (my setUpTextCount(theText))
set theBarCodeText to theText & (ASCII character theModulusCharacter)
delay 0.1


# These commented out values below display '—' & '”'
# set the clipboard to ((ASCII character 209) & theBarCodeText & (ASCII character 211) as text)


# These start & stop values are taken from a later version of the font (Barton site),
# which displays the values above as the Ascii value, but actually displays the
# characters as below, as the start & stop values.
set the clipboard to ((ASCII character 237) & theBarCodeText & (ASCII character 235) as text)


tell application "TextEdit"
activate
tell front document
tell application "System Events" to tell process "TextEdit"
keystroke "v" using command down
end tell
set the font of last paragraph of its text to "Code 128"
set the size of last paragraph of its text to 36 # 
end tell
set the clipboard to (return & return as text)
tell front document
tell application "System Events" to tell process "TextEdit"
keystroke "v" using command down
end tell
end tell
end tell
end repeat

on setUpTextCount(theText)
set eachCharacterCount to 104 # the value of the start character for Barcode 128 Set B
repeat with x from 1 to count of theText # We start counting from the first character of the actual text,and multiply it’s adjusted value by its position
set eachCharacter to item x of theText
set eachCharacterAscii to (ASCII number of eachCharacter)
if eachCharacterAscii < 127 then
set subtractAsciiOffset to 32
else
set subtractAsciiOffset to 105
end if
set eachCharacterCount to eachCharacterCount + ((eachCharacterAscii - subtractAsciiOffset) * x)
end repeat
set theModulusNumber to eachCharacterCount mod 103
set theAddOnAscii to 32


# This commented out line uses 105 as the Font example shows, but it prints non-barcode 
# characters sometimes. 
# if theModulusNumber > 94 then set theAddOnAscii to 105 


# This line below uses the difference in values as shown on site 2 (Barton site),
# but still sometimes displays non-barcode characters.
if theModulusNumber > 94 then set theAddOnAscii to 128 # Sometimes, non-barcode characters are printed!
return theModulusNumber + theAddOnAscii
end setUpTextCount



/*
 * Auteur : Joffrey VERDIER
 * Date : 08/2006
 * Légal : OpenSource © 2007 AVRANCHES
 * 
 */

using System;
using System.Collections.Generic;
using System.Text;

    public class Code128
    {
        public Code128() { }
        /// <summary>
        /// Encode la chaine en code128
        /// </summary>
        /// <param name="chaine">Chaine à transcrire</param>
        /// <returns></returns>
        public String Encode(String chaine)
        {
                    int ind = 1; 
        int checksum = 0; 
        int mini; 
        int dummy; 
        bool tableB; 
        String code128; 
        int longueur; 

        code128 = "";
        longueur = chaine.Length;


        if (longueur == 0)
        {
            Console.WriteLine("\n chaine vide");
        }
        else
        {
            for (ind = 0; ind < longueur; ind++)
            {
                if ((chaine[ind] < 32) || (chaine[ind] > 126))
                {
                    Console.WriteLine("\n chaine invalide");
                }
            }
        }


        tableB = true;
        ind = 0;

       

      

        while (ind < longueur)
        {   

       

            if (tableB == true)
            {
                if ((ind == 0) || (ind + 3 == longueur-1))
                {               
                    mini = 4;
                }
                else
                {
                    mini = 6;
                }

               

                mini = mini - 1;

               

               if ((ind + mini) <= longueur - 1)
                {
                    while (mini >= 0)
                    {
                        if ((chaine[ind + mini] < 48) || (chaine[ind + mini] > 57))
                        {
                            Console.WriteLine("\n exit");
                            break;
                        }
                        mini = mini - 1;
                    }
                }


                if (mini < 0)
                {
                    if (ind == 0)
                    {
                        code128 = Char.ToString((char) 205);

                    }
                    else
                    {
                        code128 = code128 + Char.ToString((char)199);

                    }
                    tableB = false;
                }
                else
                {

                    if (ind == 0)
                    {
                        code128 = Char.ToString((char) 204);
                    }
                }
            }

        

            if (tableB == false)
            {
                mini = 2;
                mini = mini - 1;
                if (ind + mini < longueur)
                {
                    while (mini >= 0)
                    {

                        if (((chaine[ind + mini]) < 48) || ((chaine[ind]) > 57))
                        {
                            break;
                        }
                        mini = mini - 1;
                    }
                }
                if (mini < 0)
                {
                    dummy = Int32.Parse(chaine.Substring(ind, 2));

                   

                    Console.WriteLine("\n  dummy ici : "+dummy);

                   

                    if (dummy < 95)
                    {
                        dummy = dummy + 32;
                    } else
                    {
                        dummy = dummy + 100;
                    }                 
                    code128 = code128 + (char)(dummy);

                    ind = ind + 2;
                }
                else
                {
                    code128 = code128 + Char.ToString((char) 200);
                    tableB = true;
                }
            }        
            if (tableB == true)
            {

                code128 = code128 + chaine[ind];
                ind = ind + 1;
            }
        }

        for (ind = 0; ind <= code128.Length-1; ind++)
        {
            dummy = code128[ind];
            Console.WriteLine("\n  et voila dummy : "+dummy);
            if (dummy < 127)
            {
                dummy = dummy - 32;
            }
            else
            {
                dummy = dummy - 100;
            }
            if (ind == 0)
            {
                checksum = dummy;
            }
            checksum = (checksum + (ind) * dummy) % 103;
        }

        if (checksum < 95)
        {
            checksum = checksum + 32;
        }
        else
        {
            checksum = checksum + 100;
        }
        code128 = code128 + Char.ToString((char) checksum)
                + Char.ToString((char) 206);

            

        return code128;
        }
    }

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Still after help with Barcode font issue, Please!
      • From: Steve Mills <email@hidden>
  • Prev by Date: GUI scripting
  • Next by Date: Re: Still after help with Barcode font issue, Please!
  • Previous by thread: Re: GUI scripting
  • Next by thread: Re: Still after help with Barcode font issue, Please!
  • Index(es):
    • Date
    • Thread