Exemplo n.º 1
0
 /// <summary>
 /// コンストラクタです。
 /// </summary>
 /// <param name="device"></param>
 public CharCacheManager(PPDDevice device)
 {
     this.device  = device;
     cache        = new Dictionary <char, Dictionary <float, Dictionary <string, CharCacheInfo> > >();
     sizeTextures = new Dictionary <float, Dictionary <string, SizeTextureManager> >();
     encoder      = new Direct2DImageEncoder(2048, 2048, 96);
 }
Exemplo n.º 2
0
        internal void CreateTexture(PPDDevice device, Direct2DImageEncoder encoder, SizeTextureManager sizeTextureManager)
        {
            fontScale      = PPDSetting.Setting.FontScaleDisabled ? 1 : Math.Max(1, device.Scale.X);
            ActualFontSize = FontSize * fontScale;
            TextureBase texture = null;

            switch (PPDSetting.Setting.TextureCharMode)
            {
            case TextureCharMode.D2D:
                if (d2dFailedCount > 10)
                {
                    goto case TextureCharMode.WinAPI;
                }
                texture = CreateTextureByD2D(device, encoder);
                if (texture == null)
                {
                    d2dFailedCount++;
                    goto case TextureCharMode.WinAPI;
                }
                else
                {
                    d2dFailedCount = 0;
                }
                break;

            case TextureCharMode.WinAPI:
                texture = CreateTextureByWinAPI(device);
                break;
            }
            if (texture != null)
            {
                if (PPDSetting.Setting.CharacterTexturePackingDisabled)
                {
                    Texture      = texture;
                    UV           = Vector2.Zero;
                    UVSize       = Vector2.One;
                    ActualUVSize = Vector2.One;
                    HalfPixel    = new Vector2(0.5f / t_width, 0.5f / t_height);
                }
                else
                {
                    var sizeTexture = sizeTextureManager.Write(texture, t_width, t_height, out Vector2 uv, out Vector2 uvSize, out availableSpace);
                    texture.Dispose();
                    Texture      = sizeTexture.Texture;
                    UV           = uv;
                    UVSize       = uvSize;
                    ActualUVSize = new Vector2(uvSize.X * width / t_width, uvSize.Y * height / t_height);
                    HalfPixel    = sizeTexture.HalfPixel;
                }
            }
        }
Exemplo n.º 3
0
        private TextureBase CreateTextureByD2D(PPDDevice device, Direct2DImageEncoder encoder)
        {
            var retryCount = 0;

            while (true)
            {
                try
                {
                    using (var stream = new MemoryStream())
                    {
                        encoder.Save(stream, Direct2DImageFormat.Png, new string(Character, 1), FaceName, ActualFontSize, out int width, out int height);
                        stream.Seek(0, SeekOrigin.Begin);
                        var bitmap = new Bitmap(stream);
                        Utility.PreMultiplyAlpha(bitmap);
                        var tempStream = new MemoryStream();
                        bitmap.Save(tempStream, System.Drawing.Imaging.ImageFormat.Png);
                        tempStream.Seek(0, SeekOrigin.Begin);
                        var texture = ((PPDFramework.Texture.DX9.TextureFactory)TextureFactoryManager.Factory).FromStream(device, tempStream, width, height, SharpDX.Direct3D9.Pool.SystemMemory, true);
                        this.width    = width;
                        this.height   = height;
                        this.t_width  = Utility.UpperPowerOfTwo(width);
                        this.t_height = Utility.UpperPowerOfTwo(height);
                        return(texture);
                    }
                }
                catch
                {
                    retryCount++;
                    if (retryCount >= 5)
                    {
                        break;
                    }
                }
            }
            return(null);
        }