Encadrement d'une Image

/************************************************************************
   Frame
 ************************************************************************
 Multi-language Version
 Draws a frame around an image.
 The image is made bigger of 2 * thickness of the frame.
 The frame is made of up to 3 embedded borders.
 A signature can be added into a new layer.
 The parameters can be saved into a config file : CADRE.DAT
 ************************************************************************
 05/11/2011 Habaki V1r05b: Accept a document without a Background layer
 05/11/2011 Eddy.VH V1r05: Multi-language: Deutsch
 03/11/2011 Habaki V1r05 : Multi-language: Francais, English
 30/10/2011 Habaki V1r04 : Edit a signature
 17/10/2011 Habaki V1r03 : Add a user interface
 16/10/2011 Habaki V1r02 : Adjustments
 11/10/2011 Habaki V1r01 : Creation
 ************************************************************************/
/*----------------------------------------------------------------------*
   Parameters
 *----------------------------------------------------------------------*/
var CfgFileName = "CADRE.DAT";  // Configuration file name
/*----------------------------------------------------------------------*
   Messages
 *----------------------------------------------------------------------*/
// FRANCAIS
function MsgFR() {
  this.Language = "Francais";
  this.ScriptName = "CADRE";
  this.Title= "Cadre autour d'une Image";
  this.FloatSep = ",";  // Separateur des nombres flottants
  this.White = "Blanc";
  this.Black = "Noir";
  this.FG = "Avant Plan";
  this.BG = "Arriere Plan";
  this.BottomRight = "Bas Droite";
  this.BottomLeft = "Bas Gauche";
  this.TopLeft = "Haut Gauche";
  this.TopRight= "Haut Droite";
  this.Center= "Centre";
  this.Image= "IMAGE";
  this.Document= "Document:";
  this.Height= "Hauteur:";
  this.Width= "Largeur:";
  this.S00= "Les % s'appliquent au + grand cote. Pour ignorer bordure ou texte: 0 pixels";
  this.Border= "BORDURES";
  this.Color= "Couleur:";
  this.Thickness= "Epaisseur:";
  this.Signature= "SIGNATURE";
  this.Text= "Texte:";
  this.Font= "Police:";
  this.Position= "Position:";
  this.Build= "Construire";
  this.Cancel= "Annuler";
  this.Save= "Enregistrer";
  this.Size= "Taille:";
  this.OpenADoc= "Ouvrir un Document !";
}
/*----------------------------------------------------------------------*/
// English
function MsgEN() {
  this.Language = "English";
  this.ScriptName = "FRAME";
  this.Title= "Picture Frame";
  this.FloatSep = ".";  // Separator for float numbers
  this.White = "White";
  this.Black = "Black";
  this.FG = "Foreground";
  this.BG = "Background";
  this.BottomRight = "Bottom right";
  this.BottomLeft = "Bottom left";
  this.TopLeft = "Top left";
  this.TopRight= "Top right";
  this.Center= "Center";
  this.Image= "IMAGE";
  this.Document= "Document:";
  this.Height= "Height:";
  this.Width= "Width:";
  this.S00= "% apply to the largest edge. To ignore a border or text: 0 pixels";
  this.Border= "BORDERS";
  this.Color= "Color:";
  this.Thickness= "Thickness:";
  this.Signature= "SIGNATURE";
  this.Text= "Text:";
  this.Font= "Font:";
  this.Position= "Position:";
  this.Build= "Build";
  this.Cancel= "Cancel";
  this.Save= "Save";
  this.Size= "Size:";
  this.OpenADoc= "Open a Document !";
}
/*----------------------------------------------------------------------*/
// DEUTSCH
function MsgDE() {
  this.Language = "Deutsch";
  this.ScriptName = "Rahmen";
  this.Title= "Bilderrahmen";
  this.FloatSep = ",";  // Separateur des nombres flottants
  this.White = "Weiß";
  this.Black = "Schwarz";
  this.FG = "Vordergrund";
  this.BG = "Hintergrund";
  this.BottomRight = "Unten Rechts";
  this.BottomLeft = "Unten Links";
  this.TopLeft = "Oben Links";
  this.TopRight= "Oben Rechts";
  this.Center= "Mitte";
  this.Image= "BILD";
  this.Document= "Dokument:";
  this.Height= "H\u00F6he:";
  this.Width= "Breite:";
  this.S00= "Der Prozentsatz gillt f\u00FCr die gr\u00F6ßte Dimension. 0 Pixel: Um Rahmen oder Text zu ignorieren";
  this.Border= "RAHMEN";
  this.Color= "Farbe:";
  this.Thickness= "Breite:";
  this.Signature= "SIGNATUR";
  this.Text= "Text:";
  this.Font= "Font:";
  this.Position= "Position:";
  this.Build= "Erstellen";
  this.Cancel= "Abbrechen";
  this.Save= "Speichern";
  this.Size= "Gr\u00F6ße:";
  this.OpenADoc= "\uooD6ffnen Sie ein Dokument!";
}
/*----------------------------------------------------------------------*/
// Available Languages
var MsgList = new Array(new MsgFR(), new MsgEN(), new MsgDE());
var Msg; // Current messages
/*----------------------------------------------------------------------*
   Globals
 *----------------------------------------------------------------------*/
// Color names : keep the order
var ColorArray;
// Position names : keep the order
var PositionArray;
// Font postscript names
var FontArray = new Array();
/************************************************************************
   Configuration File
 CfgSt :
 One line for language:
 L;Language
 ************************************************************************/
function Config()
{
  // Restore configuration
  var Script = new File($.fileName);
  var CfgLine;
  var Language = "";
 
  this.CfgFile = new File(Script.path + "/" + CfgFileName);
  this.CfgSt   = "";
  try{
    this.CfgFile.open("r:");
    this.CfgSt = this.CfgFile.read();
    this.CfgFile.close();
    //alert("Cfg In:<" + this.CfgSt + ">");
  
  } catch(ex) {
    this.CfgFile.close();
    //alert("Cfg In: None");
  }
  if (this.CfgSt)
    CfgLine = this.CfgSt.split("\n");
 
  // Restore language
  if (CfgLine) {
    for (b=0;b<10;b++) {
      if (CfgLine[b]) {
        Params = CfgLine[b].split(";");
        if (Params[0] == "L") {
          Language = Params[1];
        } else continue;
      }
    } // for
  }
  if (Language) {
    for (l=0;l<MsgList.length;l++) {
      if (Language == MsgList[l].Language) {
        Msg = MsgList[l];
        break;
      }
    } // for
  } else {
    Msg = MsgList[0];
  }
}
/*----------------------------------------------------------------------*
                        Save configuration
 *----------------------------------------------------------------------*/
Config.prototype.Save = function(CfgSt)
{
  if (!CfgSt) CfgSt = this.CfgSt;
  CfgSt += "L;" + Msg.Language + "\n";
 
  //alert("Cfg Out:<" + CfgSt + ">");
  try{
    this.CfgFile.open("w:");
    this.CfgFile.write(CfgSt);
    this.CfgFile.close();
  } catch(ex) {
    this.CfgFile.close();
    alert(ex.message, Msg.ScriptName);
  }
}
/************************************************************************
                        Border
 ************************************************************************/
function Bordure(
        Ep,  // Thickness in %
        Color  //
        )
{
  if (Color=='') Color=ColorArray[2];
  this.Dlg  = null;   // Dialog
  this.Ep   = Ep;   // Ep in %
  this.Color  = Color;  // Color
}
/************************************************************************
                        Signature
 ************************************************************************/
function Signature(
        Size,
        Color
        )
{
  if (Color=='') Color=ColorArray[2];
  this.Dlg  = null;   // Dialog
  this.Ep   = Size;   // Size (epaisseur)
  this.Color  = Color;  // Color Name
  this.Font  = FontArray[0];  // Font postscript name
  this.Text  = "";   // Text
  this.Position  = PositionArray[0]; // Position
}
/************************************************************************
                        Cadre
 ************************************************************************
 CfgSt :
 One line per bordure :
 B;Color;Percent\n
 B;Color;Percent\n
 B;Color;Percent\n
 One line for the signature :
 S;Color;Size;Font;Text;Position\n
 ************************************************************************/
function Cadre(
        Cfg  // Config object
 )
{
  var prc, color;
  var CfgSt, CfgLine;
  var Params;
 
  try{
    this.LName   = activeDocument.name;
    this.LHeight = activeDocument.height;
    this.LWidth  = activeDocument.width;
    this.LSize   = (this.LHeight > this.LWidth ?
                    this.LHeight : this.LWidth); // biggest edge
  } catch(e) {
    alert(Msg.OpenADoc);
    throw(3);
  }
  // Default values
 
  // 3 Borders : from inside to outside
  this.Bord = new Array(new Bordure(0.2, ColorArray[2]),
                        new Bordure(1.0, ColorArray[0]),
                        new Bordure(0.3, ColorArray[1])
                        );
  // Signature
  this.Signature = new Signature(2.0, ColorArray[1]); // Black
 
  // Restore configuration
  this.Cfg = Cfg;
  if (Cfg && (CfgSt = Cfg.CfgSt))
    CfgLine = CfgSt.split("\n");
 
  if (CfgLine) {
    for (b=0;b<10;b++) {
      if (CfgLine[b]) {
        Params = CfgLine[b].split(";");
        if (Params[0] == "B") {
          //alert("Bord CfgSt " + b + ": " + Params);
          this.Bord[b].Color = Params[1];
          this.Bord[b].Ep    = parseFloat(Params[2].replace(Msg.FloatSep,'.'));
          if (isNaN(this.Bord[b].Ep)) this.Bord[b].Ep = 0;
        } else
        if (Params[0] == "S") {
          //alert("Sign CfgSt: " + Params);
          this.Signature.Color = Params[1];
          this.Signature.Ep    = parseFloat(Params[2].replace(Msg.FloatSep,'.'));
          if (isNaN(this.Signature.Ep)) this.Signature.Ep = 0;
          this.Signature.Font  = Params[3];
          this.Signature.Text  = Params[4];
          this.Signature.Position  = Params[5];
        } else continue;
      }
    } // for
  }
}
/*----------------------------------------------------------------------*
                        Save configuration
 *----------------------------------------------------------------------*/
Cadre.prototype.CfgSave = function()
{
  var st = "";
 
  for (b=0;b<3;b++) {
    st += "B;" + this.Bord[b].Color + ";" + this.Bord[b].Ep + "\n";
  } // for
  st += "S;" + this.Signature.Color
     +  ";"  + this.Signature.Ep
     +  ";"  + this.Signature.Font
     +  ";"  + this.Signature.Text
     +  ";"  + this.Signature.Position
     +  "\n";
 
  this.Cfg.Save(st);
}
/*----------------------------------------------------------------------*
                        % to Pixels
 *----------------------------------------------------------------------*/
Cadre.prototype.PrcToPix = function(
        prc
        )
{
  var pix = Math.round(this.LSize * prc / 100);
  if (prc == 0) pix = 0;
  else
  if (pix == 0) pix = 1;
  return(pix);
}
/*----------------------------------------------------------------------*
                        Pixels to %
 *----------------------------------------------------------------------*/
Cadre.prototype.PixToPrc = function(
        Pix
        )
{
  var px = Pix * 100/ this.LSize;
 
  if (isNaN(px)) px = 0;
  return(Math.round(px * 100) / 100);
}
/*----------------------------------------------------------------------*
   Color from name
 *----------------------------------------------------------------------*/
Cadre.prototype.ColorHexValue = function(
        ColorName
 )
{
  var val;
 
  if (ColorName==ColorArray[0]) //white
    val = 'FFFFFF';
  else
  if (ColorName==ColorArray[1]) // black
    val = '000000';
  else
  if (ColorName==ColorArray[3]) // background
    val = backgroundColor.rgb.hexValue;
  else
    val = foregroundColor.rgb.hexValue;  // default
  return(val);
}
/*----------------------------------------------------------------------*
                        Init Color in Dlg
 *----------------------------------------------------------------------*/
Cadre.prototype.dialogColorInit = function(
        obj,  // object
        dlg // Color dialog
        )
{
  var ColorDlg = dlg;
  var c, c0;
 
  c0 = 0;
  for (c=0;c < ColorArray.length; c++) {
    ColorDlg.add('item', ColorArray[c]);
    if (ColorArray[c] == obj.Color) c0 = c; // Selection
  } // for
  ColorDlg.selection = c0;  // Can be set with an index
  ColorDlg.onChange = function() {
    // WARNING:selection retuns an item
    var sel = ColorDlg.selection.index; // null if none
    if (sel || sel==0) {
      //alert("Color:" + ColorDlg.items[sel].toString());
      obj.Color = ColorDlg.items[sel].toString();
    }
  }
}
/*----------------------------------------------------------------------*
                        Init Lang in Dlg
 *----------------------------------------------------------------------*/
Cadre.prototype.dialogLangInit = function(
        obj,  // object
        dlg // dialog
        )
{
  var c, c0;
  var Language;
 
  c0 = 0;
  for (c=0;c < MsgList.length; c++) {
    dlg.add('item', MsgList[c].Language);
    if (MsgList[c] == Msg) c0 = c; // Selection
  } // for
  dlg.selection = c0;  // Can be set with an index
  dlg.onChange = function() {
    // WARNING:selection retuns an item
    var sel = dlg.selection.index; // null if none
    if (sel || sel==0) {
      Language = dlg.items[sel].toString();
      //alert("Language: " + Language);
      if (Msg.Language != Language) {
        for (l=0;l<MsgList.length;l++) {
          if (Language == MsgList[l].Language) {
            Msg = MsgList[l];
            break;
          }
        } // for
        obj.Dialog.close(10); // Restart
      };
    }
  }
}
/*----------------------------------------------------------------------*
                        Init Position in Dlg
 *----------------------------------------------------------------------*/
Cadre.prototype.dialogPositionInit = function(
        obj,  // object
        dlg // Position dialog
        )
{
  var PositionDlg = dlg;
  var c, c0;
 
  c0 = 0;
  for (c=0;c < PositionArray.length; c++) {
    PositionDlg.add('item', PositionArray[c]);
    if (PositionArray[c] == obj.Position) c0 = c; // Selection
  } // for
  PositionDlg.selection = c0;  // Can be set with an index
  PositionDlg.onChange = function() {
    // WARNING:selection retuns an item
    var sel = PositionDlg.selection.index; // null if none
    if (sel || sel==0) {
      obj.Position = PositionDlg.items[sel].toString();
      //alert("Position:" + obj.Position);
    }
  }
}
/*----------------------------------------------------------------------*
                        Init Font in Dlg
 *----------------------------------------------------------------------*/
Cadre.prototype.dialogFontInit = function(
        obj,
        dlg  // Font dialog
        )
{
  var FontDlg = dlg;
  var i, i0;
 
  c0 = 0;
  for (i=0;i < FontArray.length; i++) {
    FontDlg.add('item', FontArray[i]);
    if (FontArray[i] == obj.Font) i0 = i; // Selection
  } // for
  FontDlg.selection = i0;  // Can be set with an index
  FontDlg.onChange = function() {
    // WARNING:selection retuns an item
    var sel = FontDlg.selection.index; // null if none
    if (sel || sel==0) {
      obj.Font = FontDlg.items[sel].toString();
      //alert("Font:" + obj.Font);
    }
  }
}
/*----------------------------------------------------------------------*
                        Init Ep in Dlg
 *----------------------------------------------------------------------*/
Cadre.prototype.dialogEpInit = function(
        obj,
        dlg, // Group of Ep dialog
        EpTitle
        )
{
  var This = this;
 
  if (EpTitle) dlg.MsgEp.text = EpTitle;
  var Sld = dlg.Sld;
  Sld.onChanging = function() {
    obj.Ep = Math.round(Sld.value*100)/100;
    if (isNaN(obj.Ep)) obj.Ep = 0;
    dlg.ValPrc.text = obj.Ep.toString().replace('.',Msg.FloatSep);
    dlg.ValPix.text = "" + This.PrcToPix(obj.Ep);
  }
  var Prc = dlg.ValPrc;
  Prc.onChanging = function() {
    obj.Ep = parseFloat(dlg.ValPrc.text.replace(Msg.FloatSep,'.'));
    if (isNaN(obj.Ep)) obj.Ep = 0;
    dlg.ValPix.text = "" + This.PrcToPix(obj.Ep);
    Sld.value = obj.Ep;
  }
  var Pix = dlg.ValPix;
  Pix.onChanging = function() {
    obj.Ep = This.PixToPrc(parseInt(dlg.ValPix.text));
    if (isNaN(obj.Ep)) obj.Ep = 0;
    dlg.ValPrc.text = obj.Ep.toString().replace('.',Msg.FloatSep);
    Sld.value = obj.Ep;
  }
 
  dlg.ValPrc.text = obj.Ep.toString().replace('.',Msg.FloatSep);
  dlg.ValPix.text = Math.round(This.LSize * obj.Ep/100);
  Sld.value = obj.Ep;
}
/*----------------------------------------------------------------------*
                        Init Text in Dlg
 *----------------------------------------------------------------------*/
Cadre.prototype.dialogTextInit = function(
        obj,  // object
        dlg // Text dialog
        )
{
  var TextDlg = dlg;
 
  TextDlg.onChanging = function() {
    obj.Text = TextDlg.text;
    //alert("Text:" + obj.Text);
  }
  TextDlg.text = "" + obj.Text;
}
/*----------------------------------------------------------------------*
   Dialog
 *----------------------------------------------------------------------*/
Cadre.prototype.dialogBuild = function(
        //This
 )
{
  var This = this;
 
  var myResource = "dialog{ \
    orientation: 'column',\
    alignChildren: 'fill',\
    panelLayer: Panel {\
      orientation: 'column',\
      alignChildren: 'fill',\
      text: 'IMAGE',\
      Name: Group {\
        orientation: 'row',\
        Msg: StaticText {text: 'Document:'},\
        Val: StaticText {text: ''}\
      },\
      Height: Group {\
        orientation: 'row',\
        alignChildren:  'top',\
        Msg: StaticText {text: 'Hauteur:', characters: 7},\
        Val: StaticText {text: '?'}\
      },\
      Width: Group {\
        orientation: 'row',\
        alignChildren:  'top',\
        Msg: StaticText {text: 'Largeur:', characters: 7},\
        Val: StaticText {text: '?'}\
      }\
    },\
    s00: StaticText {text: 'Commentaire'},\
    panelCadre: Panel  {\
      orientation: 'column',\
      alignChildren: 'fill',\
      text: 'BORDURES',\
      Bord1: Group {\
        orientation: 'row',\
        MsgColor: StaticText {text: 'Couleur:'},\
        Color: DropDownList {bounds: [0,0,120,20]},\
        MsgEp: StaticText {text: 'Epaisseur:'},\
        Sld : Slider {minvalue:0, maxvalue:10},\
        ValPrc: EditText {text: '2', bounds: [0,0,40,20]},\
        MsgPrc: StaticText {text: '%'},\
        ValPix: EditText {text: '2', bounds: [0,0,40,20]},\
        MsgPix: StaticText {text: 'Pixels'},\
      },\
      Bord2: Group {\
        orientation: 'row',\
        MsgColor: StaticText {text: 'Couleur:'},\
        Color: DropDownList {bounds: [0,0,120,20]},\
        MsgEp: StaticText {text: 'Epaisseur:'},\
        Sld : Slider {minvalue:0, maxvalue:10},\
        ValPrc: EditText {text: '2', bounds: [0,0,40,20]},\
        MsgPrc: StaticText {text: '%'},\
        ValPix: EditText {text: '2', bounds: [0,0,40,20]},\
        MsgPix: StaticText {text: 'Pixels'},\
      },\
      Bord3: Group {\
        orientation: 'row',\
        MsgColor: StaticText {text: 'Couleur:'},\
        Color: DropDownList {bounds: [0,0,120,20]},\
        MsgEp: StaticText {text: 'Epaisseur:'},\
        Sld : Slider {minvalue:0, maxvalue:10},\
        ValPrc: EditText {text: '2', bounds: [0,0,40,20]},\
        MsgPrc: StaticText {text: '%'},\
        ValPix: EditText {text: '2', bounds: [0,0,40,20]},\
        MsgPix: StaticText {text: 'Pixels'},\
      },\
    },\
    panelSign: Panel {\
      orientation: 'column',\
      alignChildren: 'fill',\
      text: 'SIGNATURE',\
      Text: Group {\
        MsgText: StaticText {text:  'Texte:', characters: 7},\
        Val: EditText {text: '', bounds: [0,0,400,20]}\
      },\
      ColSize: Group {\
        orientation: 'row',\
        MsgColor: StaticText {text: 'Couleur:', characters: 7},\
        Color: DropDownList {bounds: [0,0,120,20]},\
        MsgEp: StaticText {text: 'Epaisseur:'},\
        Sld : Slider {minvalue:0, maxvalue:10},\
        ValPrc: EditText {text: '2', bounds: [0,0,40,20]},\
        MsgPrc: StaticText {text: '%'},\
        ValPix: EditText {text: '2', bounds: [0,0,40,20]},\
        MsgPix: StaticText {text: 'Pixels'},\
      },\
      Font: Group {\
        orientation: 'row',\
        MsgFont: StaticText {text: 'Police:', characters: 7},\
        Font: DropDownList {bounds: [0,0,300,20]},\
      },\
      Position: Group {\
        orientation: 'row',\
        MsgPos: StaticText {text: 'Position:', characters: 7},\
        Position: DropDownList {bounds: [0,0,120,20]},\
      },\
    },\
    sign: StaticText {text: 'Habaki, Eddy 2011, V1.05'},\
    groupButtons: Group  {\
      orientation: 'row',\
      buttonOk: Button { text: 'Construire', enabled: 'false'},\
      buttonCancel: Button { text: 'Annuler'},\
      buttonSave: Button { text: 'Enregistrer'},\
      MsgLang: StaticText {bounds: [0,0,120,20]},\
      Lang: DropDownList {bounds: [0,0,120,20]},\
    }\
  };"
  var myDialog = new Window(myResource, Msg.Title);
  myDialog.cadreInstance = this;
  this.Dialog = myDialog;
 
  this.dialogLangInit(this, myDialog.groupButtons.Lang);
 
  myDialog.panelLayer.text  = Msg.Image;
  myDialog.panelLayer.Name.Msg.text = Msg.Document;
  myDialog.panelLayer.Name.Val.text = this.LName;
  myDialog.panelLayer.Height.Msg.text = Msg.Height;
  myDialog.panelLayer.Height.Val.text = this.LHeight;
  myDialog.panelLayer.Width.Msg.text = Msg.Width;
  myDialog.panelLayer.Width.Val.text = this.LWidth;
 
  myDialog.s00.text   = Msg.S00;
 
  myDialog.panelCadre.text  = Msg.Border;
  this.Bord[0].Dlg = myDialog.panelCadre.Bord1;
  this.Bord[0].Dlg.MsgColor.text = Msg.Color;
  this.dialogColorInit(this.Bord[0], this.Bord[0].Dlg.Color);
  this.dialogEpInit(this.Bord[0], this.Bord[0].Dlg, Msg.Thickness);
 
  this.Bord[1].Dlg = myDialog.panelCadre.Bord2;
  this.Bord[1].Dlg.MsgColor.text = Msg.Color;
  this.dialogColorInit(this.Bord[1], this.Bord[1].Dlg.Color);
  this.dialogEpInit(this.Bord[1], this.Bord[1].Dlg, Msg.Thickness);
 
  this.Bord[2].Dlg = myDialog.panelCadre.Bord3;
  this.Bord[2].Dlg.MsgColor.text = Msg.Color;
  this.dialogColorInit(this.Bord[2], this.Bord[2].Dlg.Color);
  this.dialogEpInit(this.Bord[2], this.Bord[2].Dlg, Msg.Thickness);
 
  this.Signature.Dlg = myDialog.panelSign;
  this.Signature.Dlg.text = Msg.Signature;
  this.Signature.Dlg.Text.MsgText.text = Msg.Text;
  this.dialogTextInit(this.Signature, this.Signature.Dlg.Text.Val);
  this.Signature.Dlg.ColSize.MsgColor.text = Msg.Color;
  this.dialogColorInit(this.Signature, this.Signature.Dlg.ColSize.Color);
  this.dialogEpInit(this.Signature, this.Signature.Dlg.ColSize, Msg.Size);
  this.Signature.Dlg.Font.MsgFont.text = Msg.Font;
  this.dialogFontInit(this.Signature, this.Signature.Dlg.Font.Font);
  this.Signature.Dlg.Position.MsgPos.text = Msg.Position;
  this.dialogPositionInit(this.Signature, this.Signature.Dlg.Position.Position);
 
  // determines return value and keyboard shortcuts
  myDialog.groupButtons.buttonOk.text = Msg.Build;
  myDialog.defaultElement = myDialog.groupButtons.buttonOk; // == return value 1
  myDialog.groupButtons.buttonCancel.text = Msg.Cancel;
  myDialog.cancelElement  = myDialog.groupButtons.buttonCancel;
  myDialog.groupButtons.buttonSave.text = Msg.Save;
  myDialog.groupButtons.buttonSave.onClick = function() {
    This.CfgSave("");
  }
  /*--------------------------------------------------*/
  return(myDialog);
}
/*----------------------------------------------------------------------*
   Get parameters from User
 *----------------------------------------------------------------------*/
Cadre.prototype.getParams = function()
{
  var myDialog = this.dialogBuild(this);
  //var OK = (myDialog.show() == 1 ? true : false);
 
  // All parameters are already updated into the objects
  return (myDialog.show());
}
/*----------------------------------------------------------------------*
   Build process
 *----------------------------------------------------------------------*/
Cadre.prototype.build = function()
{
  try{
    // Config parameters
    var BrdPix;
    var BrdPixT = 0;  // Total
    var BgColor;
    var PixPerMM;  // Pixels per mm
    var Layers = activeDocument.artLayers;
  
    PixPerMM = activeDocument.resolution / 25.4;
  
    // Layers
    var BordersL;
  
    // Unlock eventual BG layer
    b = Layers.length-1;
    if (Layers[b].isBackgroundLayer) {
        var v = Layers[b].visible;
        Layers[b].isBackgroundLayer=false;
        Layers[b].name = Msg.Image;
        Layers[b].visible = v;
    }
  
    // New white BG layer for Borders
    BgColor = backgroundColor.rgb.hexValue;
    backgroundColor.rgb.hexValue = this.ColorHexValue(ColorArray[0]); // white
    BordersL                   = Layers.add();
    BordersL.name              = Msg.Border;
    BordersL.visible           = true;
    BordersL.isBackgroundLayer = true;
    backgroundColor.rgb.hexValue = BgColor;
  
    // Borders
    for (b=0;b <3; b++) {
      if (this.Bord[b].Ep == 0) continue; // Cadre desactive
    
      // Pixel nd in border
      BrdPix  = this.PrcToPix(this.Bord[b].Ep);
      BrdPixT += BrdPix;
      //alert("Pixels:" + BrdPix);
    
      // Color
      BgColor = backgroundColor.rgb.hexValue;
      backgroundColor.rgb.hexValue = this.ColorHexValue(this.Bord[b].Color);
    
      // Agrandissement
      activeDocument.resizeCanvas(activeDocument.width  + 2 * BrdPix,
                                  activeDocument.height + 2 * BrdPix,
                                  AnchorPosition.MIDDLECENTER
                                  );
      backgroundColor.rgb.hexValue = BgColor;
    } // for
  
    // Signature
    if (this.Signature.Ep && this.Signature.Text) {
      var SignL;
      var Sign = this.Signature;
      var bounds, x, y, h, w, x0, y0;
      var pts;
    
      pts = this.PrcToPix(Sign.Ep) / (PixPerMM * 0.3527);  // points
      SignL = Layers.add();
      SignL.name              = Msg.Signature;
      SignL.visible           = true;
      SignL.kind              = LayerKind.TEXT;
      SignL.textItem.font     = Sign.Font;
      SignL.textItem.size     = pts;
      SignL.textItem.color.rgb.hexValue = this.ColorHexValue(Sign.Color);
      SignL.textItem.contents = Sign.Text;
    
      bounds = SignL.bounds;
      w = bounds[2] - bounds[0];
      h = bounds[3] - bounds[1];
      x0 = bounds[0];
      y0 = bounds[1];
    
      // New position
      if (Sign.Position==PositionArray[4]) {
        // Center
        x = this.LWidth/2  + BrdPixT - w/2;
        y = this.LHeight/2 + BrdPixT - h/2;
      }
      else
      if (Sign.Position==PositionArray[3]) {
        // Top left
        x =                BrdPixT     + h;
        y =                BrdPixT     + h;
      }
      else
      if (Sign.Position==PositionArray[2]) {
        // Top right
        x = this.LWidth  + BrdPixT - w - h;
        y =                BrdPixT     + h;
      }
      else
      if (Sign.Position==PositionArray[1]) {
        // Bottom left
        x =                BrdPixT     + h;
        y = this.LHeight + BrdPixT     - 2*h;
      }
      else
      if (Sign.Position==PositionArray[0]) {
        // Bottom right
        x = this.LWidth  + BrdPixT - w - h;
        y = this.LHeight + BrdPixT     - 2*h;
      }
      SignL.translate(x - x0, y - y0);
    }
  
  } catch(ex){
    alert(ex.message, Msg.ScriptName);
  }
}
/************************************************************************
                        Execution
 ************************************************************************/
// Save current configuration
var RulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var BGColor = app.backgroundColor.rgb.hexValue;

try {
  for(i=0;i < app.fonts.length; i++) {
    FontArray[i] = app.fonts[i].postScriptName;
  }
 
  // Restore configuration
  var Cfg = new Config();
  var cadre;
  var Dialog;
  var show;
 
  // Loop for language
  for(;;) {
    // Needs Msg from the configuration
    // Color names : keep the order
    ColorArray = new Array(Msg.White, Msg.Black, Msg.FG, Msg.BG);
    // Position names : keep the order
    PositionArray = new Array(Msg.BottomRight, Msg.BottomLeft,
                              Msg.TopRight, Msg.TopLeft, Msg.Center);
  
    cadre = new Cadre(Cfg);
    Dialog = cadre.dialogBuild();
    show = Dialog.show();
    // show: 1=OK, 2=Cancel, 10=Reinit for language
    if (show == 1) {
      cadre.build();
      // cadre.CfgSave(); // Manual Save only
      break;
    } else
    if (show==2) break;
    else Cfg.CfgSt = "";
  } // for
 
} catch(ex) {
  if (ex && ex != 3) alert(ex.message, "FRAME");
}
// Restore current configuration
app.preferences.rulerUnits = RulerUnits;
app.backgroundColor.rgb.hexValue = BGColor;
/*----------------------------------------------------------------------*/

 

Créer un blog gratuit sur over-blog.com - Contact - C.G.U. - Rémunération en droits d'auteur - Signaler un abus - Articles les plus commentés