Exemple #1
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;
                }
            }
        }
Exemple #2
0
        private CharCacheInfo GetCharCacheInfo(char c, float fontSize, string faceName)
        {
            Dictionary <float, Dictionary <string, CharCacheInfo> > sizeCache;
            Dictionary <string, CharCacheInfo> faceCache;
            CharCacheInfo info;

            lock (cache)
            {
                if (!cache.TryGetValue(c, out sizeCache))
                {
                    sizeCache = new Dictionary <float, Dictionary <string, CharCacheInfo> >();
                    cache[c]  = sizeCache;
                }
            }
            lock (sizeCache)
            {
                if (!sizeCache.TryGetValue(fontSize, out faceCache))
                {
                    faceCache           = new Dictionary <string, CharCacheInfo>();
                    sizeCache[fontSize] = faceCache;
                }
            }
            lock (faceCache)
            {
                if (!faceCache.TryGetValue(faceName, out info) || info.Disposed)
                {
                    info = new CharCacheInfo(fontSize, faceName, c);
                    SizeTextureManager sizeTextureManager = null;
                    if (!PPDSetting.Setting.CharacterTexturePackingDisabled)
                    {
                        sizeTextureManager = GetSizeTextureManager(fontSize, faceName);
                    }
                    info.CreateTexture(device, encoder, sizeTextureManager);
                    faceCache[faceName] = info;
                }
            }
            return(info);
        }
Exemple #3
0
        private SizeTextureManager GetSizeTextureManager(float fontSize, string faceName)
        {
            Dictionary <string, SizeTextureManager> faceTextures;
            SizeTextureManager sizeTextureManager;

            lock (sizeTextures)
            {
                if (!sizeTextures.TryGetValue(fontSize, out faceTextures))
                {
                    faceTextures           = new Dictionary <string, SizeTextureManager>();
                    sizeTextures[fontSize] = faceTextures;
                }
            }
            lock (faceTextures)
            {
                if (!faceTextures.TryGetValue(faceName, out sizeTextureManager))
                {
                    sizeTextureManager     = new SizeTextureManager(device);
                    faceTextures[faceName] = sizeTextureManager;
                }
            }
            return(sizeTextureManager);
        }