示例#1
0
 /// <summary>
 /// Persist changes to the Font object
 /// </summary>
 /// <param name="createUser"></param>
 /// <returns></returns>
 internal BaseResponse UpdateFont(FontResult fontlist, long auditUserId, string auditWorkstation)
 {
     try
     {
         _cardManService.UpdateFont(fontlist, auditUserId, auditWorkstation);
         return(new BaseResponse(ResponseType.SUCCESSFUL,
                                 "",
                                 ""));
     }
     catch (Exception ex)
     {
         log.Error(ex);
         return(new BaseResponse(ResponseType.ERROR,
                                 "Error processing request, please try again.",
                                 log.IsDebugEnabled || log.IsTraceEnabled ? ex.Message : ""));
     }
 }
示例#2
0
        /// <summary>
        /// get product details to edit record.
        /// </summary>
        /// <param name="Productid"></param>
        /// <returns></returns>
        public Response <FontResult> GetFont(int fontid)
        {
            FontResult productlist = new FontResult();

            try
            {
                productlist = _cardManService.GetFont(fontid);
                return(new Response <FontResult>(productlist, ResponseType.SUCCESSFUL,
                                                 "",
                                                 ""));
            }
            catch (Exception ex)
            {
                log.Error(ex);
                return(new Response <FontResult>(null,
                                                 ResponseType.ERROR,
                                                 "Error when processing request.",
                                                 log.IsDebugEnabled || log.IsTraceEnabled ? ex.Message : ""));
            }
        }
示例#3
0
 /// <summary>
 /// Persist Font to the DB.
 /// </summary>
 /// <param name="productlist"></param>
 /// <param name="auditUserId"></param>
 /// <param name="auditWorkstation"></param>
 /// <returns></returns>
 internal Response <long?> InsertFont(FontResult fontresult, long auditUserId, string auditWorkstation)
 {
     try
     {
         return(new Response <long?>(_cardManService.InsertFont(fontresult, auditUserId, auditWorkstation),
                                     ResponseType.SUCCESSFUL, "", ""));
     }
     catch (BaseIndigoException bex)
     {
         log.Error(bex);
         return(new Response <long?>(null,
                                     ResponseType.UNSUCCESSFUL,
                                     bex.Message,
                                     log.IsDebugEnabled || log.IsTraceEnabled ? bex.ToString() : ""));
     }
     catch (Exception ex)
     {
         log.Error(ex);
         return(new Response <long?>(null,
                                     ResponseType.ERROR,
                                     "An error occured during processing your request, please try again.",
                                     log.IsDebugEnabled || log.IsTraceEnabled ? ex.ToString() : ""));
     }
 }
示例#4
0
        public static FontResult FindFont(string fontName, int fontSize, bool isBold, bool isItalic, int charset, int first, int last, int AA)
        {
            // TODO: replace BMFont by AngelCode with a more cross-platform approach?
            try
            {
                string conf = BMFCTemplate
                              .Replace("{FONT_NAME}", fontName)
                              .Replace("{FONT_CHARSET}", charset.ToString())
                              .Replace("{FONT_SIZE}", fontSize.ToString())
                              .Replace("{IS_BOLD}", isBold ? "1" : "0")
                              .Replace("{IS_ITALIC}", isItalic ? "1" : "0")
                              .Replace("{CHARACTER_RANGE}", first.ToString() + "-" + last.ToString())

                              // this is wrong, but kinda works.
                              .Replace("{CLEAR_TYPE}", (AA > 0) ? "1" : "0");

                string  AppDir   = AppDomain.CurrentDomain.BaseDirectory;
                string  confPath = Path.Combine(AppDir, "temp.bmfc");
                string  texPath  = Path.Combine(AppDir, "temp_0.png");
                string  xmlPath  = Path.Combine(AppDir, "temp.fnt");
                string  bmfgPath = Path.Combine(AppDir, "bmfont64.exe");
                string  bmfArgs  = "-c temp.bmfc -o temp.fnt";
                Process bmf      = new Process();
                bmf.StartInfo.FileName         = bmfgPath;
                bmf.StartInfo.WorkingDirectory = AppDir;
                bmf.StartInfo.Arguments        = bmfArgs;
                File.WriteAllText(confPath, conf);
                bmf.Start();
                bmf.WaitForExit();
                bmf.Dispose();
                File.Delete(confPath);

                // I do the dummy thing so we can delete the file right away.
                Image  dummy  = Image.FromFile(texPath);
                Bitmap fntTex = new Bitmap(dummy);
                dummy.Dispose();
                File.Delete(texPath);

                byte[] fontalpha = new byte[fntTex.Width * fntTex.Height];
                int    ww        = fntTex.Width;
                int    hh        = fntTex.Height;

                for (int yy = 0; yy < hh; yy++)
                {
                    for (int xx = 0; xx < ww; xx++)
                    {
                        // GetPixel is slow, I know.
                        byte alpha = fntTex.GetPixel(xx, yy).A;
                        fontalpha[xx + (yy * ww)] = alpha;
                    }
                }

                fntTex.Dispose();

                XDocument fntXml = XDocument.Load(xmlPath);
                File.Delete(xmlPath);

                FontResult ret = new FontResult();
                ret.Texture = fontalpha;
                ret.Width   = ww;
                ret.Height  = hh;
                ret.Glyphs  = new int[256][];
                for (int i = 0; i < ret.Glyphs.Length; i++)
                {
                    ret.Glyphs[i] = new int[6];
                }

                foreach (var glyph in fntXml.Root.Element("chars").Elements("char"))
                {
                    int id = int.Parse(glyph.Attribute("id").Value);

                    int x        = int.Parse(glyph.Attribute("x").Value);
                    int y        = int.Parse(glyph.Attribute("y").Value);
                    int width    = int.Parse(glyph.Attribute("width").Value);
                    int height   = int.Parse(glyph.Attribute("height").Value);
                    int yoffset  = int.Parse(glyph.Attribute("yoffset").Value);
                    int xadvance = int.Parse(glyph.Attribute("xadvance").Value);

                    ret.Glyphs[id][0] = x;
                    ret.Glyphs[id][1] = y;
                    ret.Glyphs[id][2] = width;
                    ret.Glyphs[id][3] = height;
                    ret.Glyphs[id][4] = xadvance;
                    ret.Glyphs[id][5] = yoffset;
                }

                return(ret);
            }
            catch (Exception e)
            {
                Console.WriteLine();
                Console.WriteLine("-- FONT FAIL --");
                Console.WriteLine(e.ToString());
            }

            return(null);
        }