private static Dictionary <string, CharSet> ReadCharSets(XmlDocument doc)
        {
            XmlNodeList charsets = doc.SelectNodes("//charset");

            Dictionary <string, CharSet> sets = new Dictionary <string, CharSet>();

            foreach (XmlNode cs in charsets)
            {
                CharSet charset = new CharSet()
                {
                    Name = cs.Attributes["name"].Value
                };
                XmlNodeList chars = cs.SelectNodes("char");
                foreach (XmlNode cd in chars)
                {
                    CharDef chardef = new CharDef()
                    {
                        Name   = cd.Attributes["name"].Value,
                        X      = int.Parse(cd.Attributes["x"].Value),
                        Y      = int.Parse(cd.Attributes["y"].Value),
                        Width  = int.Parse(cd.Attributes["width"].Value),
                        Height = int.Parse(cd.Attributes["height"].Value),
                        Image  = cd.Attributes["img"].Value
                    };
                    charset.Characters.Add(chardef.Name[0], chardef);
                }

                sets.Add(charset.Name, charset);
            }
            return(sets);
        }
Пример #2
0
 public MSI()
 {
     base.bdType           = BarcodeType.MSIPLESSEY;
     base.bdTypeName       = name;
     base.bdStyle          = 0x1a;
     base.bdLongBars       = 0;
     base.bdCharBitNum     = 8;
     base.bdCharNum        = 10;
     base.bdTextLen        = 0;
     base.bdCentralCharInd = 0;
     base.bdBarExtNum      = 2;
     byte[] buffer = new byte[4];
     buffer[0]            = 1;
     buffer[1]            = 3;
     base.bdBarExt        = buffer;
     base.bdSpaceExtNum   = 2;
     buffer               = new byte[4];
     buffer[0]            = 1;
     buffer[1]            = 3;
     base.bdSpaceExt      = buffer;
     base.bdInterCharExt  = 0;
     base.bdLeftMargin    = 9;
     base.bdTopMargin     = 1;
     base.bdRightMargin   = 9;
     base.bdBottomMargin  = 1;
     base.bdCentralMargin = 0;
     CharDef[][] defArray = new CharDef[3][];
     defArray[0]        = _chardef_msi;
     base.bdCharset     = defArray;
     base.bdCharsetSel  = null;
     base.bdStyle2      = 0;
     base.bdTextLen2    = 0;
     base.bdCharset2    = null;
     base.bdCharsetSel2 = null;
 }
Пример #3
0
 public EAN8()
 {
     base.bdType           = BarcodeType.EAN8;
     base.bdTypeName       = "EAN-8";
     base.bdStyle          = 0xabe;
     base.bdLongBars       = 7;
     base.bdCharBitNum     = 7;
     base.bdCharNum        = 10;
     base.bdTextLen        = 8;
     base.bdCentralCharInd = 4;
     base.bdBarExtNum      = 1;
     byte[] buffer = new byte[4];
     buffer[0]            = 1;
     base.bdBarExt        = buffer;
     base.bdSpaceExtNum   = 1;
     buffer               = new byte[4];
     buffer[0]            = 1;
     base.bdSpaceExt      = buffer;
     base.bdInterCharExt  = 0;
     base.bdLeftMargin    = 7;
     base.bdTopMargin     = 1;
     base.bdRightMargin   = 7;
     base.bdBottomMargin  = 1;
     base.bdCentralMargin = 0;
     CharDef[][] defArray = new CharDef[3][];
     defArray[0]        = EANUPC._chardef_eana;
     defArray[1]        = EANUPC._chardef_eanc;
     base.bdCharset     = defArray;
     base.bdCharsetSel  = null;
     base.bdStyle2      = 0;
     base.bdTextLen2    = 0;
     base.bdCharset2    = null;
     base.bdCharsetSel2 = null;
 }
Пример #4
0
 public EAN13_2()
 {
     base.bdType           = BarcodeType.EAN13_2;
     base.bdTypeName       = "EAN-13 + 2";
     base.bdStyle          = 0xf3e;
     base.bdLongBars       = 7;
     base.bdCharBitNum     = 7;
     base.bdCharNum        = 10;
     base.bdTextLen        = 13;
     base.bdCentralCharInd = 7;
     base.bdBarExtNum      = 1;
     byte[] buffer = new byte[4];
     buffer[0]            = 1;
     base.bdBarExt        = buffer;
     base.bdSpaceExtNum   = 1;
     buffer               = new byte[4];
     buffer[0]            = 1;
     base.bdSpaceExt      = buffer;
     base.bdInterCharExt  = 0;
     base.bdLeftMargin    = 11;
     base.bdTopMargin     = 1;
     base.bdRightMargin   = 7;
     base.bdBottomMargin  = 1;
     base.bdCentralMargin = 8;
     base.bdCharset       = new CharDef[][] { EANUPC._chardef_eana, EANUPC._chardef_eanb, EANUPC._chardef_eanc };
     base.bdCharsetSel    = EANUPC._ean_sel;
     base.bdStyle2        = 0xce;
     base.bdTextLen2      = 2;
     CharDef[][] defArray = new CharDef[3][];
     defArray[0]        = EANUPC._chardef_add2a;
     defArray[1]        = EANUPC._chardef_add2b;
     base.bdCharset2    = defArray;
     base.bdCharsetSel2 = EANUPC._add2_sel;
 }
Пример #5
0
 public Code39()
 {
     base.bdType           = BarcodeType.CODE39;
     base.bdTypeName       = "Code 39";
     base.bdStyle          = 0x18;
     base.bdLongBars       = 0;
     base.bdCharBitNum     = 9;
     base.bdCharNum        = 0x2b;
     base.bdTextLen        = 0;
     base.bdCentralCharInd = 0;
     base.bdBarExtNum      = 2;
     byte[] buffer = new byte[4];
     buffer[0]            = 1;
     buffer[1]            = 3;
     base.bdBarExt        = buffer;
     base.bdSpaceExtNum   = 2;
     buffer               = new byte[4];
     buffer[0]            = 1;
     buffer[1]            = 3;
     base.bdSpaceExt      = buffer;
     base.bdInterCharExt  = 2;
     base.bdLeftMargin    = 10;
     base.bdTopMargin     = 1;
     base.bdRightMargin   = 10;
     base.bdBottomMargin  = 1;
     base.bdCentralMargin = 0;
     CharDef[][] defArray = new CharDef[3][];
     defArray[0]        = _chardef_3of9;
     base.bdCharset     = defArray;
     base.bdCharsetSel  = null;
     base.bdStyle2      = 0;
     base.bdTextLen2    = 0;
     base.bdCharset2    = null;
     base.bdCharsetSel2 = null;
 }
Пример #6
0
Файл: UPCE.cs Проект: ikvm/test
 public UPCE()
 {
     base.bdType           = BarcodeType.UPCE;
     base.bdTypeName       = "UPC-E";
     base.bdStyle          = 0xa9e;
     base.bdLongBars       = 3;
     base.bdCharBitNum     = 7;
     base.bdCharNum        = 10;
     base.bdTextLen        = 8;
     base.bdCentralCharInd = 0;
     base.bdBarExtNum      = 1;
     byte[] buffer = new byte[4];
     buffer[0]            = 1;
     base.bdBarExt        = buffer;
     base.bdSpaceExtNum   = 1;
     buffer               = new byte[4];
     buffer[0]            = 1;
     base.bdSpaceExt      = buffer;
     base.bdInterCharExt  = 0;
     base.bdLeftMargin    = 9;
     base.bdTopMargin     = 1;
     base.bdRightMargin   = 7;
     base.bdBottomMargin  = 1;
     base.bdCentralMargin = 0;
     CharDef[][] defArray = new CharDef[3][];
     defArray[0]        = _chardef_upcea;
     defArray[1]        = _chardef_upceb;
     base.bdCharset     = defArray;
     base.bdCharsetSel  = _upce_sel;
     base.bdStyle2      = 0;
     base.bdTextLen2    = 0;
     base.bdCharset2    = null;
     base.bdCharsetSel2 = null;
 }
Пример #7
0
 public void SetAll(CharDef charDef, int offset, int width, uint style)
 {
     this._charDef = charDef;
     this._offset  = offset;
     this._width   = width;
     this._style   = style;
 }
Пример #8
0
 public UPCA_5()
 {
     base.bdType           = BarcodeType.UPCA_5;
     base.bdTypeName       = "UPC-A + 5";
     base.bdStyle          = 0xf3e;
     base.bdLongBars       = 0x1f;
     base.bdCharBitNum     = 7;
     base.bdCharNum        = 10;
     base.bdTextLen        = 12;
     base.bdCentralCharInd = 6;
     base.bdBarExtNum      = 1;
     byte[] buffer = new byte[4];
     buffer[0]            = 1;
     base.bdBarExt        = buffer;
     base.bdSpaceExtNum   = 1;
     buffer               = new byte[4];
     buffer[0]            = 1;
     base.bdSpaceExt      = buffer;
     base.bdInterCharExt  = 0;
     base.bdLeftMargin    = 9;
     base.bdTopMargin     = 1;
     base.bdRightMargin   = 5;
     base.bdBottomMargin  = 1;
     base.bdCentralMargin = 9;
     base.bdCharset       = new CharDef[][] { EANUPC._chardef_eana, EANUPC._chardef_eanb, EANUPC._chardef_eanc };
     base.bdCharsetSel    = EANUPC._ean_sel;
     base.bdStyle2        = 0xce;
     base.bdTextLen2      = 5;
     CharDef[][] defArray = new CharDef[3][];
     defArray[0]        = EANUPC._chardef_add2a;
     defArray[1]        = EANUPC._chardef_add2b;
     base.bdCharset2    = defArray;
     base.bdCharsetSel2 = EANUPC._add5_sel;
 }
Пример #9
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            charDef = new CharDef();

#if SCREENSHOTMODE
            graphics.PreferredBackBufferWidth  = 1280;
            graphics.PreferredBackBufferHeight = 720;
            graphics.ApplyChanges();
#endif

            base.Initialize();
        }
Пример #10
0
        private void DrawBatchString(float tx, float ty, string text, LColor c,
                                     int startIndex, int endIndex)
        {
            if (isClose)
            {
                return;
            }

            float x = tx, y = ty;

            displayList.GLBegin();

            CharDef lastCharDef = null;

            char[] data = text.ToCharArray();
            for (int i = 0; i < data.Length; i++)
            {
                int id = data[i];
                if (id == '\n')
                {
                    x  = 0;
                    y += GetLineHeight();
                    continue;
                }
                if (id >= chars.Length)
                {
                    continue;
                }
                CharDef charDef = chars[id];
                if (charDef == null)
                {
                    continue;
                }

                if (lastCharDef != null)
                {
                    x += lastCharDef.GetKerning(id);
                }
                lastCharDef = charDef;

                if ((i >= startIndex) && (i <= endIndex))
                {
                    charDef.Draw(x, y, 0, c);
                }

                x += charDef.advance;
            }

            displayList.GLEnd();
        }
Пример #11
0
        public FontDef(string FilePath)
        {
            XmlDocument tDoc = new XmlDocument();

            tDoc.Load(FilePath);

            XmlElement tRoot = tDoc.DocumentElement;

            _TexWidth  = Convert.ToInt32(tRoot.GetAttribute("TexWidth"));
            _TexHeight = Convert.ToInt32(tRoot.GetAttribute("TexHeight"));
            _AntiAlias = (System.Drawing.Text.TextRenderingHint)Convert.ToInt32(tRoot.GetAttribute("AntiAlias"));

            foreach (XmlNode x in tRoot)
            {
                XmlElement tObj = x as XmlElement;
                if (tObj != null)
                {
                    CharDef tChar = new CharDef();
                    tChar.Advance     = Convert.ToInt32(tObj.GetAttribute("Advance"));
                    tChar.Baseline    = Convert.ToInt32(tObj.GetAttribute("Baseline"));
                    tChar.Character   = Convert.ToChar(tObj.GetAttribute("Character"));
                    tChar.ImageMargin = Convert.ToInt32(tObj.GetAttribute("ImageMargin"));
                    tChar.FontColor   = Color.FromArgb(Convert.ToInt32(tObj.GetAttribute("FontColor")));

                    FontStyle tStyle = FontStyle.Regular;
                    if (Convert.ToBoolean(tObj.GetAttribute("Bold")))
                    {
                        tStyle = FontStyle.Bold;
                    }
                    if (Convert.ToBoolean(tObj.GetAttribute("Italic")))
                    {
                        tStyle |= FontStyle.Italic;
                    }
                    if (Convert.ToBoolean(tObj.GetAttribute("Strikeout")))
                    {
                        tStyle |= FontStyle.Strikeout;
                    }
                    if (Convert.ToBoolean(tObj.GetAttribute("Underline")))
                    {
                        tStyle |= FontStyle.Underline;
                    }
                    tChar.SrcFont = new Font(tObj.GetAttribute("FontName"), Convert.ToSingle(tObj.GetAttribute("FontSize")), tStyle);

                    _CharList.Add(tChar);
                }
            }

            RenderTexture();
        }
Пример #12
0
        private void Update(object sender, System.EventArgs e)
        {
            frameLabel.Text = "Frame: " + InputManager.CurrentFrame;

            var c = CharMgr.GetPlayerCharacter(PlayerMgr.GetMainPlayer());

            xLabel.Text      = "Pos X: " + c?.loc.X;
            yLabel.Text      = "Pos Y: " + c?.loc.Y;
            xSpeedLabel.Text = "Spd X: " + c?.traj.X;
            ySpeedLabel.Text = "Spd Y: " + c?.traj.Y;

            MouseState mouse = InputManager.GetActualMouse();

            mouseXLabel.Text = "Pos X: " + mouse.X;
            mouseYLabel.Text = "Pos Y: " + mouse.Y;

            var charAnim = c?.anim;

            animNameLabel.Text  = "Name: " + charAnim?.animName;
            animKeyLabel.Text   = "Key: " + charAnim?.key;
            animFrameLabel.Text = "Frame: " + charAnim?.frame;

            KeyFrame frame;

            try
            {
                MonsterDef mDef    = MonsterCatalog.catalog[c.monsterIdx];
                CharDef    charDef = CharDefMgr.charDefList[mDef.defIdx];
                Animation  anim    = charDef.animation[charAnim.anim];
                frame = anim.keyFrame[charAnim.key];
            }
            catch
            {
                frame = null;
            }

            animFrameDurationLabel.Text = "Duration: " + frame?.duration;

            if (NeedsClose)
            {
                NeedsClose = false;
                Close();
            }
            else
            {
                Invalidate();
            }
        }
Пример #13
0
        public int GetWidth(string text)
        {
            if (text == null)
            {
                return(0);
            }
            int     width       = 0;
            CharDef lastCharDef = null;

            for (int i = 0, n = text.Length; i < n; i++)
            {
                int id = text[i];
                if (id == '\n')
                {
                    width = 0;
                    continue;
                }
                if (id >= chars.Length)
                {
                    continue;
                }
                CharDef charDef = chars[id];
                if (charDef == null)
                {
                    continue;
                }
                if (lastCharDef != null)
                {
                    width += lastCharDef.GetKerning(id);
                }
                lastCharDef = charDef;
                if (i < n - 1)
                {
                    width += charDef.advance;
                }
                else
                {
                    width += charDef.width;
                }
                width = MathUtils.Max(charDef.width, width);
            }

            return(width);
        }
Пример #14
0
        private CharDef ParseChar(string line)
        {
            CharDef         def    = new CharDef(this);
            StringTokenizer tokens = new StringTokenizer(line, " =");

            tokens.NextToken();
            tokens.NextToken();
            def.id = short.Parse(tokens.NextToken());

            if (def.id < 0)
            {
                return(null);
            }
            if (def.id > DEFAULT_MAX_CHAR)
            {
                throw new Exception(def.id + " > " + DEFAULT_MAX_CHAR);
            }

            tokens.NextToken();
            def.tx = short.Parse(tokens.NextToken());
            tokens.NextToken();
            def.ty = short.Parse(tokens.NextToken());
            tokens.NextToken();
            def.width = short.Parse(tokens.NextToken());
            tokens.NextToken();
            def.height = short.Parse(tokens.NextToken());
            tokens.NextToken();
            def.xoffset = short.Parse(tokens.NextToken());
            tokens.NextToken();
            def.yoffset = short.Parse(tokens.NextToken());
            tokens.NextToken();
            def.advance = short.Parse(tokens.NextToken());

            if (def.id != ' ')
            {
                lineHeight = MathUtils.Max(def.height + def.yoffset, lineHeight);
            }

            return(def);
        }
Пример #15
0
        public FontDef(string FilePath)
        {
            XmlDocument tDoc = new XmlDocument();
            tDoc.Load(FilePath);

            XmlElement tRoot = tDoc.DocumentElement;
            _TexWidth = Convert.ToInt32(tRoot.GetAttribute("TexWidth"));
            _TexHeight = Convert.ToInt32(tRoot.GetAttribute("TexHeight"));
            _AntiAlias = (System.Drawing.Text.TextRenderingHint)Convert.ToInt32(tRoot.GetAttribute("AntiAlias"));

            foreach (XmlNode x in tRoot)
            {
                XmlElement tObj = x as XmlElement;
                if (tObj != null)
                {
                    CharDef tChar = new CharDef();
                    tChar.Advance = Convert.ToInt32(tObj.GetAttribute("Advance"));
                    tChar.Baseline = Convert.ToInt32(tObj.GetAttribute("Baseline"));
                    tChar.Character = Convert.ToChar(tObj.GetAttribute("Character"));
                    tChar.ImageMargin = Convert.ToInt32(tObj.GetAttribute("ImageMargin"));
                    tChar.FontColor = Color.FromArgb(Convert.ToInt32(tObj.GetAttribute("FontColor")));

                    FontStyle tStyle = FontStyle.Regular;
                    if(Convert.ToBoolean(tObj.GetAttribute("Bold")))
                        tStyle = FontStyle.Bold;
                    if(Convert.ToBoolean(tObj.GetAttribute("Italic")))
                        tStyle |= FontStyle.Italic;
                    if (Convert.ToBoolean(tObj.GetAttribute("Strikeout")))
                        tStyle |= FontStyle.Strikeout;
                    if (Convert.ToBoolean(tObj.GetAttribute("Underline")))
                        tStyle |= FontStyle.Underline;
                    tChar.SrcFont = new Font(tObj.GetAttribute("FontName"), Convert.ToSingle(tObj.GetAttribute("FontSize")), tStyle);

                    _CharList.Add(tChar);
                }
            }

            RenderTexture();
        }
Пример #16
0
 public UPCE_2()
 {
     base.bdType           = BarcodeType.UPCE_2;
     base.bdTypeName       = "UPC-E + 2";
     base.bdStyle          = 0xe9e;
     base.bdLongBars       = 3;
     base.bdCharBitNum     = 7;
     base.bdCharNum        = 10;
     base.bdTextLen        = 8;
     base.bdCentralCharInd = 0;
     base.bdBarExtNum      = 1;
     byte[] buffer = new byte[4];
     buffer[0]            = 1;
     base.bdBarExt        = buffer;
     base.bdSpaceExtNum   = 1;
     buffer               = new byte[4];
     buffer[0]            = 1;
     base.bdSpaceExt      = buffer;
     base.bdInterCharExt  = 0;
     base.bdLeftMargin    = 9;
     base.bdTopMargin     = 1;
     base.bdRightMargin   = 5;
     base.bdBottomMargin  = 1;
     base.bdCentralMargin = 7;
     CharDef[][] defArray = new CharDef[3][];
     defArray[0]        = UPCE._chardef_upcea;
     defArray[1]        = UPCE._chardef_upceb;
     base.bdCharset     = defArray;
     base.bdCharsetSel  = UPCE._upce_sel;
     base.bdStyle2      = 0xce;
     base.bdTextLen2    = 2;
     defArray           = new CharDef[3][];
     defArray[0]        = EANUPC._chardef_add2a;
     defArray[1]        = EANUPC._chardef_add2b;
     base.bdCharset2    = defArray;
     base.bdCharsetSel2 = EANUPC._add2_sel;
 }
Пример #17
0
        private void Parse(Stream file)
        {
            if (displays == null)
            {
                displays = new ArrayMap(DEFAULT_MAX_CHAR);
            }
            else
            {
                displays.Clear();
            }
            try {
                StreamReader ins = new StreamReader(file,
                                                    System.Text.Encoding.UTF8);
                info   = ins.ReadLine();
                common = ins.ReadLine();
                page   = ins.ReadLine();

                ArrayMap kerning = new ArrayMap(
                    64);
                List <CharDef> charDefs = new List <CharDef>(
                    DEFAULT_MAX_CHAR);

                int  maxChar = 0;
                bool done    = false;
                for (; !done;)
                {
                    string line = ins.ReadLine();
                    if (line == null)
                    {
                        done = true;
                    }
                    else
                    {
                        if (line.StartsWith("chars c"))
                        {
                        }
                        else if (line.StartsWith("char"))
                        {
                            CharDef def = ParseChar(line);
                            if (def != null)
                            {
                                maxChar = MathUtils.Max(maxChar, def.id);
                                charDefs.Add(def);
                            }
                        }
                        if (line.StartsWith("kernings c"))
                        {
                        }
                        else if (line.StartsWith("kerning"))
                        {
                            StringTokenizer tokens = new StringTokenizer(line, " =");
                            tokens.NextToken();
                            tokens.NextToken();
                            short first = short.Parse(tokens.NextToken());
                            tokens.NextToken();
                            int second = int.Parse(tokens.NextToken());
                            tokens.NextToken();
                            int          offset = int.Parse(tokens.NextToken());
                            List <short> values = (List <short>)kerning.GetValue(first);
                            if (values == null)
                            {
                                values = new List <short>();
                                kerning.Put(first, values);
                            }
                            values.Add((short)((offset << 8) | second));
                        }
                    }
                }

                this.chars = new CharDef[maxChar + 1];

                for (IEnumerator <CharDef> iter = charDefs.GetEnumerator(); iter.MoveNext();)
                {
                    CharDef def = (CharDef)iter.Current;
                    chars[def.id] = def;
                }
                ArrayMap.Entry[] entrys = kerning.ToEntrys();
                for (int j = 0; j < entrys.Length; j++)
                {
                    ArrayMap.Entry entry      = entrys[j];
                    short          first      = (short)entry.GetKey();
                    List <short>   valueList  = (List <short>)entry.GetValue();
                    short[]        valueArray = new short[valueList.Count];
                    int            i          = 0;
                    for (IEnumerator <short> valueIter = valueList.GetEnumerator(); valueIter
                         .MoveNext(); i++)
                    {
                        valueArray[i] = (short)valueIter.Current;
                    }
                    chars[first].kerning = valueArray;
                }
            } catch (IOException e) {
                Log.Exception(e);
                throw new Exception("Invalid font file: " + file);
            }
        }
Пример #18
0
        private CharDef ParseChar(string line)
        {
            CharDef def = new CharDef(this);
            StringTokenizer tokens = new StringTokenizer(line, " =");

            tokens.NextToken();
            tokens.NextToken();
            def.id = short.Parse(tokens.NextToken());

            if (def.id < 0) {
            return null;
            }
            if (def.id > DEFAULT_MAX_CHAR) {
            throw new Exception(def.id + " > " + DEFAULT_MAX_CHAR);
            }

            tokens.NextToken();
            def.tx = short.Parse(tokens.NextToken());
            tokens.NextToken();
            def.ty = short.Parse(tokens.NextToken());
            tokens.NextToken();
            def.width = short.Parse(tokens.NextToken());
            tokens.NextToken();
            def.height = short.Parse(tokens.NextToken());
            tokens.NextToken();
            def.xoffset = short.Parse(tokens.NextToken());
            tokens.NextToken();
            def.yoffset = short.Parse(tokens.NextToken());
            tokens.NextToken();
            def.advance = short.Parse(tokens.NextToken());

            if (def.id != ' ') {
            lineHeight = MathUtils.Max(def.height + def.yoffset, lineHeight);
            }

            return def;
        }
Пример #19
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Removes a PUA definition via matching of codepoints.
		/// </summary>
		/// <param name="charDef">The character definition to find and remove.</param>
		/// ------------------------------------------------------------------------------------
		public void RemovePuaDefinition(CharDef charDef)
		{
			m_PuaDefs.RemoveAll(delegate(CharDef x) { return x.code == charDef.code; });
		}
Пример #20
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Creates a PUA Character object
 /// </summary>
 /// <param name="charDef">The character definition</param>
 /// ------------------------------------------------------------------------------------
 public IPuaCharacter Create(CharDef charDef)
 {
     return(new PUACharacter(charDef));
 }
Пример #21
0
		/// <summary>
		/// Makes a PUACharcter using the SIL.FieldWorks.Common.FwUtils.CharDef.
		/// </summary>
		/// <param name="puaChar">A <code>CharDef</code> taken from xml file.</param>
		public PUACharacter(CharDef puaChar) : this(puaChar.code, puaChar.data)
		{
		}
Пример #22
0
		/// <summary>
		/// Constructs a UCDCharacter based off a copy of the given puaChar.
		/// </summary>
		/// <param name="puaChar"></param>
		public UCDCharacter(CharDef puaChar) : base (puaChar)
		{
		}
Пример #23
0
 public void CopyFrom(CharDef charDef)
 {
     this.bcCharCode = charDef.GetCharCode();
     this.bcStripes  = charDef.GetStripes();
 }
Пример #24
0
        protected override void Initialize()
        {
            base.Initialize();

            _charDef = new CharDef();
        }
Пример #25
0
		/// <summary>
		/// Constructs a new BidiCharacter, copying all the values from <c>puaChar</c>
		/// </summary>
		/// <param name="puaChar"></param>
		public BidiCharacter(CharDef puaChar) : base (puaChar) {}
		public void SerializeAndDeserialize()
		{
			IWritingSystem ws = m_wsf.get_Engine("tl");
			int wsIdTl = m_wsf.GetWsFromStr("tl");
			ws.Locale = 13321;
			ws.DefaultMonospace = "Courier New";
			ws.DefaultSansSerif = "Arial";
			ws.DefaultBodyFont = "Charis SIL";
			ws.DefaultSerif = "Times New Roman";
			ws.set_Name(m_wsIdEn, "Tagalog");
			ws.set_Name(wsIdTl, "Tagalog");
			ws.set_Abbr(m_wsIdEn, "TGL");

			ICollation coll = CollationClass.Create();
			coll.WinLCID = 1033;
			coll.WinCollation = "Latin1_General_CI_AI";
			coll.set_Name(m_wsIdEn, "Default Collation");
			coll.WritingSystemFactory = m_wsf;

			ws.set_Collation(0, coll);

			LanguageDefinition langDef = new LanguageDefinition(ws);
			langDef.BaseLocale = "en_US";
			langDef.XmlWritingSystem.WritingSystem.IcuLocale = "tl";
			langDef.LocaleName = "Tagalog";
			langDef.LocaleScript = "";
			langDef.LocaleCountry = "";
			langDef.LocaleVariant = "";
			langDef.XmlWritingSystem.WritingSystem.Locale = 13321;
			langDef.CollationElements = "\"&amp; B &lt; ...";
			langDef.ValidChars = "abcdefg";
			langDef.LocaleResources = @"
				zoneStrings {
					{
						'Europe/London',
						'Greenwich Mean Time',
				  }
				}";
			CharDef[] charDefs = new CharDef[2];
			charDefs[0] = new CharDef(0xF170, "COMBINING SNAKE BELOW;Mn;202;NSM;;;;");
			charDefs[1] = new CharDef(0xF210, "LATIN SMALL LETTER P WITH STROKE;Ll;0;L;;;;");
			langDef.PuaDefinitions = charDefs;
			FileName[] fonts = new FileName[4];
			fonts[0] = new FileName("arial.ttf");
			fonts[1] = new FileName("arialbd.ttf");
			fonts[2] = new FileName("ariali.ttf");
			fonts[3] = new FileName("arialbi.ttf");
			langDef.Fonts = fonts;
			langDef.Keyboard = new FileName("Tagalog.kmx");
			langDef.EncodingConverter = new EncodingConverter("SIL_IPA93.tec.vbs", "SIL-IPA93.tec");

			string tmpFileName = Path.GetTempFileName();
			langDef.Serialize(tmpFileName);

			LanguageDefinitionFactory otherIcuWs = new LanguageDefinitionFactory();
			LanguageDefinitionFactory.WritingSystemFactory = m_wsf;
			otherIcuWs.Deserialize(tmpFileName);
			ILanguageDefinition newLangDef = otherIcuWs.LanguageDefinition;
			IWritingSystem deserializedWs = newLangDef.WritingSystem;
			ICollation deserializedColl = newLangDef.GetCollation(0);

			StreamReader reader = new StreamReader(tmpFileName);
			string line = reader.ReadLine();
			while (line != null)
			{
				Console.WriteLine(line);
				line = reader.ReadLine();
			}
			reader.Close();
			File.Delete(tmpFileName);

			Assert.AreEqual(ws.Locale, deserializedWs.Locale);
			Assert.AreEqual(ws.IcuLocale, deserializedWs.IcuLocale);
			Assert.AreEqual(ws.DefaultSansSerif, deserializedWs.DefaultSansSerif);
			Assert.AreEqual(ws.DefaultBodyFont, deserializedWs.DefaultBodyFont);
			Assert.AreEqual(ws.get_Name(m_wsIdEn), deserializedWs.get_Name(m_wsIdEn));
			Assert.AreEqual(coll.WinLCID, deserializedColl.WinLCID);
			Assert.AreEqual(coll.WinCollation, deserializedColl.WinCollation);
		// ENHANCE: Add ValidChars to the interface
		// Assert.AreEqual(ws.ValidChars, deserializedWs.ValidChars);
			Assert.AreEqual(coll.get_Name(m_wsIdEn), deserializedColl.get_Name(m_wsIdEn));
		}
Пример #27
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Creates a Bidi Character object
 /// </summary>
 /// <param name="charDef">The character definition</param>
 /// ------------------------------------------------------------------------------------
 IUcdCharacter IBidiCharacterFactory.Create(CharDef charDef)
 {
     return(new BidiCharacter(charDef));
 }
Пример #28
0
        private void DrawBatchString(float tx, float ty, string text, LColor c,
                                     int startIndex, int endIndex)
        {
            if (isClose)
            {
                return;
            }

            if (displays.Size() > DEFAULT_MAX_CHAR)
            {
                displays.Clear();
            }

            lazyHashCode = 1;

            if (c != null)
            {
                lazyHashCode = LSystem.Unite(lazyHashCode, c.r);
                lazyHashCode = LSystem.Unite(lazyHashCode, c.g);
                lazyHashCode = LSystem.Unite(lazyHashCode, c.b);
                lazyHashCode = LSystem.Unite(lazyHashCode, c.a);
            }

            string key = text + lazyHashCode;

            Display display = (Display)displays.Get(key);

            if (display == null)
            {
                int x = 0, y = 0;

                displayList.GLBegin();
                displayList.SetBatchPos(tx, ty);

                if (c != null)
                {
                    displayList.SetImageColor(c);
                }

                CharDef lastCharDef = null;
                char[]  data        = text.ToCharArray();
                for (int i = 0; i < data.Length; i++)
                {
                    int id = data[i];
                    if (id == '\n')
                    {
                        x  = 0;
                        y += GetLineHeight();
                        continue;
                    }
                    if (id >= chars.Length)
                    {
                        continue;
                    }
                    CharDef charDef = chars[id];
                    if (charDef == null)
                    {
                        continue;
                    }

                    if (lastCharDef != null)
                    {
                        x += lastCharDef.GetKerning(id);
                    }
                    lastCharDef = charDef;

                    if ((i >= startIndex) && (i <= endIndex))
                    {
                        charDef.Draw(x, y);
                    }

                    x += charDef.advance;
                }

                if (c != null)
                {
                    displayList.SetImageColor(LColor.white);
                }

                displayList.GLEnd();

                display = new Display();

                display.cache  = displayList.NewBatchCache();
                display.text   = text;
                display.width  = 0;
                display.height = 0;

                displays.Put(key, display);
            }
            else if (display.cache != null)
            {
                display.cache.x = tx;
                display.cache.y = ty;
                LTextureBatch.Commit(displayList, display.cache);
            }
        }
Пример #29
0
        public bool NextBars(Bars bars, CharDef charDefBuffer)
        {
            int     num;
            uint    num2;
            uint    num3;
            CharDef charDef = charDefBuffer;

            if ((this._acText == null) || (this._acText.Length == 0))
            {
                return(false);
            }
            if (((this._spec.bdStyle & 0x400) != null) && ((this._acText2 == null) || (this._acText2.Length == 0)))
            {
                return(false);
            }
            if (((!this._bInAddOn && ((this._spec.bdStyle & 2) == null)) || ((this._spec.bdStyle2 & 2) == null)) && ((this._cPrevChars > 0) || this._bPrevSpecialChar))
            {
                this._nmPrev += this._spec.bdInterCharExt;
            }
            if (!this._bInAddOn)
            {
                num3 = 4;
                if ((this._cPrevChars == 0) && !this._bPrevSpecialChar)
                {
                    num3 |= 1;
                }
            }
            else
            {
                num3 = 8;
                if ((this._cPrevChars == 0) && !this._bPrevSpecialChar)
                {
                    num3 |= 2;
                }
            }
            if (((this._cPrevChars == 0) && ((!this._bInAddOn && ((this._spec.bdStyle & 0x1000) != null)) || (this._bInAddOn && ((this._spec.bdStyle2 & 0x1000) != null)))) && (this._bPrevSpecialChar && !this._bPrev2ndStartChar))
            {
                if (!this._bInAddOn)
                {
                    charDef = this._spec.CalcCharDef(this._spec.bdCharset, this._spec.bdCharsetSel, this._acText, -5);
                    if (((this._spec.bdStyle & 0x800) != null) && ((this._spec.bdLongBars & 1) != 0))
                    {
                        num3 |= 0x10;
                    }
                }
                else
                {
                    charDef = this._spec.CalcCharDef2(this._spec.bdCharset2, this._spec.bdCharsetSel2, this._acText2, -5);
                }
                this._bPrevSpecialChar  = true;
                this._bPrev2ndStartChar = true;
            }
            else if (((this._cPrevChars == 0) && ((!this._bInAddOn && ((this._spec.bdStyle & 8) != null)) || (this._bInAddOn && ((this._spec.bdStyle2 & 8) != null)))) && !this._bPrevSpecialChar)
            {
                if (!this._bInAddOn)
                {
                    charDef = this._spec.CalcCharDef(this._spec.bdCharset, this._spec.bdCharsetSel, this._acText, -1);
                    if (((this._spec.bdStyle & 0x800) != null) && ((this._spec.bdLongBars & 1) != 0))
                    {
                        num3 |= 0x10;
                    }
                }
                else
                {
                    charDef = this._spec.CalcCharDef2(this._spec.bdCharset2, this._spec.bdCharsetSel2, this._acText2, -1);
                }
                this._bPrevSpecialChar = true;
            }
            else if ((!this._bInAddOn && ((this._spec.bdStyle & 0x20) != null)) && ((this._cPrevChars == this._spec.bdCentralCharInd) && !this._bPrevSpecialChar))
            {
                if (!this._bInAddOn)
                {
                    charDef = this._spec.CalcCharDef(this._spec.bdCharset, this._spec.bdCharsetSel, this._acText, -2);
                    if (((this._spec.bdStyle & 0x800) != null) && ((this._spec.bdLongBars & 4) != 0))
                    {
                        num3 |= 0x10;
                    }
                }
                else
                {
                    charDef = this._spec.CalcCharDef2(this._spec.bdCharset2, this._spec.bdCharsetSel2, this._acText2, -2);
                }
                this._bPrevSpecialChar = true;
            }
            else if ((((!this._bInAddOn && ((this._spec.bdStyle & 0x10) != null)) && (this._cPrevChars == this._acText.Length)) || ((this._bInAddOn && ((this._spec.bdStyle2 & 0x10) != null)) && (this._cPrevChars == this._acText2.Length))) && !this._bPrevSpecialChar)
            {
                if (!this._bInAddOn)
                {
                    charDef = this._spec.CalcCharDef(this._spec.bdCharset, this._spec.bdCharsetSel, this._acText, -3);
                    if (((this._spec.bdStyle & 0x800) != null) && ((this._spec.bdLongBars & 2) != 0))
                    {
                        num3 |= 0x10;
                    }
                }
                else
                {
                    charDef = this._spec.CalcCharDef2(this._spec.bdCharset2, this._spec.bdCharsetSel2, this._acText2, -3);
                }
                this._bPrevSpecialChar = true;
            }
            else if (((!this._bInAddOn && ((this._spec.bdStyle & 0x40) != null)) || (this._bInAddOn && ((this._spec.bdStyle2 & 0x40) != null))) && (!this._bPrevSpecialChar && ((!this._bInAddOn && (this._cPrevChars < this._acText.Length)) || (this._bInAddOn && (this._cPrevChars < this._acText2.Length)))))
            {
                if (!this._bInAddOn)
                {
                    charDef = this._spec.CalcCharDef(this._spec.bdCharset, this._spec.bdCharsetSel, this._acText, -4);
                }
                else
                {
                    charDef = this._spec.CalcCharDef2(this._spec.bdCharset2, this._spec.bdCharsetSel2, this._acText2, -4);
                }
                this._bPrevSpecialChar = true;
            }
            else if (((!this._bInAddOn && (this._cPrevChars < this._acText.Length)) || (this._bInAddOn && (this._cPrevChars < this._acText2.Length))) && ((!this._bInAddOn && ((this._spec.bdStyle & 1) != null)) || (this._bInAddOn && ((this._spec.bdStyle2 & 1) != null))))
            {
                CharDef def2;
                CharDef def3;
                if (!this._bInAddOn)
                {
                    def2 = this._spec.CalcCharDef(this._spec.bdCharset, this._spec.bdCharsetSel, this._acText, this._cPrevChars);
                    def3 = this._spec.CalcCharDef(this._spec.bdCharset, this._spec.bdCharsetSel, this._acText, this._cPrevChars + 1);
                }
                else
                {
                    def2 = this._spec.CalcCharDef2(this._spec.bdCharset, this._spec.bdCharsetSel2, this._acText2, this._cPrevChars);
                    def3 = this._spec.CalcCharDef2(this._spec.bdCharset, this._spec.bdCharsetSel2, this._acText2, this._cPrevChars + 1);
                }
                charDef.SetCharCode(def2.GetCharCode());
                charDef._BCSETNUMSTRIPE(this._spec.bdCharBitNum << 1);
                charDef.SetStripes(0);
                for (num = 0; num < this._spec.bdCharBitNum; num++)
                {
                    num2 = CharDef._BCTURNSTRIPETOSPACE(def3.BCGETSTRIPE(num));
                    charDef._BCSETSTRIPE(num * 2, num2);
                    num2 = def2.BCGETSTRIPE(num);
                    charDef._BCSETSTRIPE((num * 2) + 1, num2);
                }
                this._cPrevChars      += 2;
                this._bPrevSpecialChar = false;
            }
            else
            {
                if ((this._bInAddOn || (this._cPrevChars >= this._acText.Length)) && (!this._bInAddOn || (this._cPrevChars >= this._acText2.Length)))
                {
                    if (!this._bInAddOn && ((this._spec.bdStyle & 0x400) != null))
                    {
                        this._bInAddOn          = true;
                        this._cPrevChars        = 0;
                        this._bPrevSpecialChar  = false;
                        this._bPrev2ndStartChar = false;
                        this._nmPrev           += this._spec.bdCentralMargin * this._spec.bdBarExt[0];
                        return(this.NextBars(bars, charDefBuffer));
                    }
                    num3 = 0;
                    return(false);
                }
                CharDef def4 = null;
                if (this._bInAddOn)
                {
                    for (num = this._cPrevChars; num < this._acText2.Length; num++)
                    {
                        def4 = this._spec.CalcCharDef2(this._spec.bdCharset2, this._spec.bdCharsetSel2, this._acText2, num);
                        if (def4 != null)
                        {
                            break;
                        }
                    }
                }
                else
                {
                    num = this._cPrevChars;
                    while (num < this._acText.Length)
                    {
                        def4 = this._spec.CalcCharDef(this._spec.bdCharset, this._spec.bdCharsetSel, this._acText, num);
                        if (def4 != null)
                        {
                            break;
                        }
                        num++;
                    }
                    if (((this._cPrevChars == 0) && ((this._spec.bdStyle & 0x800) != null)) && ((this._spec.bdLongBars & 8) != 0))
                    {
                        num3 |= 0x10;
                    }
                    else if (((num == (this._acText.Length - 1)) && ((this._spec.bdStyle & 0x800) != null)) && ((this._spec.bdLongBars & 0x10) != 0))
                    {
                        num3 |= 0x10;
                    }
                }
                if (def4 == null)
                {
                    this._cPrevChars = num;
                    return(this.NextBars(bars, charDefBuffer));
                }
                this._cPrevChars = num + 1;
                charDef          = charDefBuffer;
                charDef.CopyFrom(def4);
                charDef._BCSETNUMSTRIPE(this._spec.bdCharBitNum);
                this._bPrevSpecialChar = false;
            }
            int offset = this._nmPrev;
            int width  = 0;

            for (num = 0; num < charDef.BCGETNUMSTRIPE(); num++)
            {
                num2 = charDef.BCGETSTRIPE(num);
                if (CharDef.BCSTRIPEISBAR(num2))
                {
                    if ((this._spec.bdStyle & 0x10000) != null)
                    {
                        width += this._spec.bdBarExt[0];
                    }
                    else
                    {
                        width += this._spec.bdBarExt[CharDef.BCSTRIPEWTHIND(num2)];
                    }
                }
                else if ((this._spec.bdStyle & 0x10000) != null)
                {
                    width += this._spec.bdSpaceExt[0];
                }
                else
                {
                    width += this._spec.bdSpaceExt[CharDef.BCSTRIPEWTHIND(num2)];
                }
            }
            this._nmPrev = offset + width;
            bars.SetAll(charDef, offset, width, num3);
            return(true);
        }
Пример #30
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Sets a PUA definition
		/// </summary>
		/// <param name="i">Zero-based index into the list of custom characters</param>
		/// <param name="code">Character code</param>
		/// <param name="data">Character definition</param>
		/// <exception cref="IndexOutOfRangeException">If <paramref name="i"/> is less than 0 or
		/// greater than or equal to <see cref="PuaDefinitionCount"/></exception>
		/// ------------------------------------------------------------------------------------
		public void UpdatePuaDefinition(int i, int code, string data)
		{
			m_PuaDefs[i] = new CharDef(code, data);
		}
Пример #31
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Adds a PUA definition
		/// </summary>
		/// ------------------------------------------------------------------------------------
		public void AddPuaDefinition(CharDef charDef)
		{
			foreach (CharDef def in m_PuaDefs)
			{
				if (def.code == charDef.code)
					return;
			}
			m_PuaDefs.Add(charDef);
		}
Пример #32
0
        public static void DrawFrameTo(AnimationManager anim, Graphics g, bool drawDebugInfo)
        {
            List <Renderable> renderObjects = new List <Renderable>(anim.CurrentTimeBlock.Objects);

            renderObjects.Sort((o1, o2) => o1.ZOrder.CompareTo(o2.ZOrder));

            foreach (Renderable o in renderObjects)
            {
                if (o.Started && !o.Finished)
                {
                    if (o is Animation)
                    {
                        Animation a = (Animation)o;

                        Rectangle animDest = new Rectangle(a.X - a.CurrentFrame.BaseX, a.Y - a.CurrentFrame.BaseY, a.CurrentFrame.Width, a.CurrentFrame.Height);

                        Image img = ResourceManager.Instance.Get(a.CurrentFrame.Image);
                        if (a.Alpha < 1)
                        { // apply alpha
                            ImageAttributes ia = new ImageAttributes();
                            ColorMatrix     cm = new ColorMatrix();
                            cm.Matrix00 = cm.Matrix11 = cm.Matrix22 = cm.Matrix44 = 1;
                            cm.Matrix33 = a.Alpha;
                            ia.SetColorMatrix(cm);
                            g.DrawImage(img, animDest, a.CurrentFrame.X, a.CurrentFrame.Y, a.CurrentFrame.Width, a.CurrentFrame.Height, GraphicsUnit.Pixel, ia);//, imgAttr);
                        }
                        else
                        {
                            g.DrawImage(img, animDest, a.CurrentFrame.X, a.CurrentFrame.Y, a.CurrentFrame.Width, a.CurrentFrame.Height, GraphicsUnit.Pixel);//, imgAttr);
                        }

                        /*g.DrawImage(img, new Rectangle(a.X, a.Y, a.CurrentFrame.Width, a.CurrentFrame.Height),
                         *               new Rectangle(a.CurrentFrame.X, a.CurrentFrame.Y, a.CurrentFrame.Width, a.CurrentFrame.Height),
                         *               GraphicsUnit.Pixel); */

                        if (drawDebugInfo)
                        {
                            g.DrawRectangle(Pens.Red, new Rectangle(a.X - 1, a.Y - 1, 2, 2));


                            int origx = (int)a.GetDebugInfo("origx");
                            int origy = (int)a.GetDebugInfo("origy");

                            foreach (AnimAttribute attr in a.Attributes)
                            {
                                if (attr.Started && attr.Name == "moveTo")
                                {
                                    int moveX = int.Parse(attr.Properties["x"]);
                                    int moveY = int.Parse(attr.Properties["y"]);

                                    g.DrawLine(new Pen(Color.FromArgb(128, Color.Red)), new Point(origx, origy), new Point(moveX, moveY));
                                }
                            }
                        }
                    }
                    else if (o is Text)
                    {
                        bool escapeNextCharacter = false;

                        Text txt        = (Text)o;
                        int  charOffset = 0;
                        foreach (char c in txt.TextString)
                        {
                            if (c == '^')
                            {
                                escapeNextCharacter = true;
                            }
                            else
                            {
                                if (txt.Definition.CharacterSet.Characters.ContainsKey(c))
                                {
                                    CharDef cc  = txt.Definition.CharacterSet.Characters[c];
                                    Image   img = ResourceManager.Instance.Get(cc.Image);

                                    Rectangle src;
                                    if (escapeNextCharacter)
                                    {
                                        CharDef space = txt.Definition.CharacterSet.Characters[' '];
                                        src = new Rectangle(space.X, space.Y, cc.Width, cc.Height);
                                    }
                                    else
                                    {
                                        src = new Rectangle(cc.X, cc.Y, cc.Width, cc.Height);
                                    }

                                    if (o.Alpha < 1)
                                    { // apply alpha
                                        ImageAttributes ia = new ImageAttributes();
                                        ColorMatrix     cm = new ColorMatrix();
                                        cm.Matrix00 = cm.Matrix11 = cm.Matrix22 = cm.Matrix44 = 1;
                                        cm.Matrix33 = o.Alpha;
                                        ia.SetColorMatrix(cm);


                                        g.DrawImage(img, new Rectangle(txt.X + charOffset, txt.Y, cc.Width, cc.Height),
                                                    src.X, src.Y, src.Width, src.Height, GraphicsUnit.Pixel, ia);     //, imgAttr);
                                    }
                                    else
                                    {
                                        g.DrawImage(img, new Rectangle(txt.X + charOffset, txt.Y, cc.Width, cc.Height),
                                                    src.X, src.Y, src.Width, src.Height, GraphicsUnit.Pixel);     //, imgAttr);
                                    }

                                    charOffset         += (cc.Width + 1);
                                    escapeNextCharacter = false;
                                }
                            }
                        }
                    }
                }
            }
        }