Completed
Last Updated: 28 Sep 2018 10:18 by Dimitar
ADMIN
Hristo
Created on: 25 Sep 2018 06:59
Category: UI Framework
Type: Bug Report
1
FIX. RadControl - font set with a GraphicsUnit.Pixel is measured and painted as with GraphicsUnit.Point
How to reproduce: this.radLabel1.Font = new System.Drawing.Font("Arial", 20F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel);

Workaround: 
public class MyRadLabel : RadLabel
{
    public override string ThemeClassName
    {
        get
        {
            return typeof(RadLabel).FullName;
        }
    }

    protected override RadLabelElement CreateLabelElement()
    {
        return new MyRadLabelElement();
    }
}

public class MyRadLabelElement : RadLabelElement
{
    protected override Type ThemeEffectiveType
    {
        get
        {
            return typeof(RadLabelElement);
        }
    }

    protected override void CreateChildElements()
    {
        base.CreateChildElements();

        MyTextPrimitive textPrimitive = new MyTextPrimitive();
        textPrimitive.Alignment = ContentAlignment.MiddleLeft;
        textPrimitive.BindProperty(TextPrimitive.TextProperty, this, RadLabelElement.TextProperty, PropertyBindingOptions.TwoWay);
        textPrimitive.BindProperty(AlignmentProperty, this, RadLabelElement.TextAlignmentProperty, PropertyBindingOptions.OneWay);
        textPrimitive.SetValue(ImageAndTextLayoutPanel.IsTextPrimitiveProperty, true);
        textPrimitive.AutoEllipsis = true;
        textPrimitive.TextWrap = true;

        ImageAndTextLayoutPanel layoutPanel = this.FindDescendant<ImageAndTextLayoutPanel>();
        if (layoutPanel != null)
        {
            layoutPanel.Children.RemoveAt(1);
            layoutPanel.Children.Add(textPrimitive);
        }
    }
}

public class MyTextPrimitive : TextPrimitive
{
    public override Font GetScaledFont(float scale)
    {
        Screen screen = Screen.PrimaryScreen;
        SizeF startScale = new SizeF(1.0f, 1.0f);
        if (RadControl.EnableDpiScaling)
        {
            startScale = NativeMethods.GetMonitorDpi(screen, NativeMethods.DpiType.Effective);
        }

        SizeF paintScale = new SizeF(scale / startScale.Width, scale / startScale.Height);
        Font font = this.Font ?? Control.DefaultFont;
        string key = paintScale.ToString() + font.FontFamily.Name + font.Size + font.Style.ToString() + font.Unit.ToString() + font.GdiCharSet.ToString() + font.GdiVerticalFont.ToString();

        if (this.ScaledFontsCache.ContainsKey(key))
        {
            return this.ScaledFontsCache[key];
        }

        Font scaledFont = new Font(font.FontFamily, font.Size * paintScale.Height, font.Style, font.Unit, font.GdiCharSet, font.GdiVerticalFont);
        this.ScaledFontsCache.Add(key, scaledFont);

        return scaledFont;
    }
}
0 comments