public void AddFontProcessor(String Extension, IFontProcessor Processor) { fontProcessors.Add(Extension, Processor); }
public Font GetFont(String File, PixelColor ForeColor, PixelColor BackColor) { ResourceInfoFont info; info.Name = File; if (BackColor != PixelColor.Black) { info.Fore = ForeColor; info.Back = BackColor; } else { info.Fore = PixelColor.White; info.Back = PixelColor.Black; } Font font = new Font(engine); font.Info = new FontInfo(); font.Info.Font = File.ToLower(); font.Info.ForeColor = ForeColor; font.Info.BackColor = BackColor; font.Info.UseBackColor = !(BackColor.a == 255 && BackColor.r == 0 && BackColor.g == 0 && BackColor.b == 0); if (fonts.ContainsKey(info)) { font.charInfo = fonts[info].charInfo; font.sprite = fonts[info].sprite; font.offset = fonts[info].offset; font.height = fonts[info].height; return(font); } FilePath path = File; if (!fontProcessors.ContainsKey(path.Extension)) { return(null); } engine.IncreaseLoadingCount(); IFontProcessor processor = (IFontProcessor)Activator.CreateInstance(fontProcessors[path.Extension].GetType()); processor.Process((string)path); Log.Debug("load \"" + path.FullPath + "\""); SlimDX.Direct3D9.Texture tex = engine.Device.CreateTexture(MakePowerOfTwo(processor.Size.x), MakePowerOfTwo(processor.Size.y)); SlimDX.Direct3D9.SurfaceDescription desc = tex.GetLevelDescription(0); MemoryUsage += desc.Width * desc.Height * 4; SlimDX.DataRectangle data = tex.LockRectangle(0, SlimDX.Direct3D9.LockFlags.Discard); System.IO.MemoryStream systemCopy = new System.IO.MemoryStream(); processor.Render(systemCopy, data.Pitch, ForeColor, BackColor); processor.Render(data.Data, data.Pitch, ForeColor, BackColor); tex.UnlockRectangle(0); //// debug output //System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(processor.Size.x, processor.Size.y, System.Drawing.Imaging.PixelFormat.Format32bppArgb); //System.Drawing.Imaging.BitmapData bmpdata = bmp.LockBits(new System.Drawing.Rectangle(0, 0, processor.Size.x, processor.Size.y), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); //byte[] bytes = new byte[processor.Size.y * bmpdata.Stride]; //systemCopy.Seek(0, System.IO.SeekOrigin.Begin); //for (int y = 0; y < processor.Size.y; y++) //{ // systemCopy.Read(bytes, y * bmpdata.Stride, processor.Size.x * 4); //} //System.Runtime.InteropServices.Marshal.Copy(bytes, 0, bmpdata.Scan0, bytes.Length); //bmp.UnlockBits(bmpdata); //bmp.Save("c:\\font.png"); //bmp.Dispose(); SpriteFrame frame = new SpriteFrame(this, tex, processor.Size, systemCopy.ToArray()); font.sprite = new Sprite(this, "", frame); font.sprite.Resolution = processor.Factor; font.charInfo = processor.CharInfo; font.offset = processor.Offset; font.height = processor.Size.y; engine.DecreaseLoadingCount(); fonts.Add(info, font); return(font); }
public virtual void AddProcessor(String Extension, IFontProcessor Processor) { Log.Info(" Add resource processor for '" + Extension + "': " + Processor.GetType().Name); resourceManager.AddFontProcessor(Extension, Processor); }