We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

SfRichTextBoxAdv: FontSize always seems to be 75% smaller than what I specify

I'm kind of at my wits end trying to figure out what's going on:

If I, for example, use the SfRichTextBoxAdv control with, say, Font Family set to Calibri and Font Size set to 12, the text I type is clearly smaller than 12 point.  Indeed, the text displayed in the SfRichTextBoxAdv control always seems to be 75% of the size I've specified.

I tested this in the sample project (Syncfusion.SampleBrowser.UWP.RichTextEditor) with the same results.  To duplicate it:

- Build an launch Syncfusion.SampleBrowser.UWP.RichTextEditor
- Create a new document and add three lines, each with a different font size: 14, 16 and 18
- Save the document as a docx file
- Load the document into Word
- The three lines will have font sizes of 10.5, 12 and 13.5, all of which are 75% of the requested sizes above

Any help appreciated.

Cheers,

Cam

3 Replies

VM Venkatesan Mani Syncfusion Team February 4, 2017 07:12 AM UTC

Hi Cam,

Thank you for contacting Syncfusion support.

In our SfRichTextBoxAdv control, conventions for all the properties is Pixel units. In order to provide options for FontSize property in Points units, you can implement IValueConverter for Pixel to Point value conversion and vice versa in your property binding.

Please find the example code below.

C# 
public class PixelToPointConverter : IValueConverter 
{ 
    /// <summary> 
    /// Converts the Pixel value to Point. 
    /// </summary> 
    /// <param name="value">The value.</param> 
    /// <param name="targetType">The targert type.</param> 
    /// <param name="parameter">The converter parameter</param> 
    /// <param name="language">The language.</param> 
    /// <returns>The converted Point value</returns> 
    public object Convert(object value, Type targetType, object parameter, string language) 
    { 
        double fontSize = (double)value; 
        return (fontSize * 72) / 96 ; 
    } 
    /// <summary> 
    /// Converts Point to Pixel.  
    /// </summary> 
    /// <param name="value">The value.</param> 
    /// <param name="targetType">The targert type.</param> 
    /// <param name="parameter">The converter parameter</param> 
    /// <param name="language">The language.</param> 
    /// <returns>The converted Pixel value.</returns> 
    public object ConvertBack(object value, Type targetType, object parameter, string language) 
    { 
        double fontSize = (double)value; 
        return (fontSize * 96) / 72; 
    } 
} 

XAML 
<ribbon:SfRibbonComboBox IsTabStop="False" Height="27" Width="63" Background="Transparent" Foreground="Transparent" x:Name="FontSizeCombo" Margin="6 0 12 0" SelectedValue="{Binding ElementName=richTextBox, Path=Selection.CharacterFormat.FontSize, Mode=TwoWay, Converter={StaticResource PixelToPointConverter} }"> 
<!--ComboBox values--> 
</ribbon:SfRibbonComboBox> 

We have also prepared a sample to demonstrate the same. Please find the sample from following link.

Sample Link: 
Sample.zip

Try running the sample and let us know if this helps you.

Regards,
Venkatesan M. 



CS Cam Stevenson February 4, 2017 03:05 PM UTC

Awesome - thanks very much for your timely help.

I did find in addition to these changes that I needed to make an additional change for the TextBox that lies underneath the SfRibbonComboBox, since it displays a string representation of the font size from the rich edit control (in pixels, as you point out).

I added another converter:

   public class PixelToPointStringConverter : IValueConverter
    {
        /// <summary> 
        /// Converts the Pixel value to a string representation of the Point value. 
        /// </summary> 
        /// <param name="value">The value.</param> 
        /// <param name="targetType">The targert type.</param> 
        /// <param name="parameter">The converter parameter</param> 
        /// <param name="language">The language.</param> 
        /// <returns>The converted Point value</returns> 
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            double fontSize = (double)value;
            return ((fontSize * 72) / 96).ToString(CultureInfo.InvariantCulture);
        }
        /// <summary> 
        /// Converts string representation of Point to Pixel.  
        /// </summary> 
        /// <param name="value">The value.</param> 
        /// <param name="targetType">The target type.</param> 
        /// <param name="parameter">The converter parameter</param> 
        /// <param name="language">The language.</param> 
        /// <returns>The converted Pixel value.</returns> 
        public object ConvertBack(object value, Type targetType, object parameter, string language)
        {
            double fontSize = double.Parse((string)value);
            return (fontSize * 96) / 72;
        }
    }

And then used it for the text box:

                            <TextBox IsTabStop="False" Canvas.ZIndex="4" IsReadOnly="True" FontSize="12" Padding="8 4 2 4" Text="{Binding ElementName=richTextBox, Path=Selection.CharacterFormat.FontSize, Mode=OneWay, Converter={StaticResource PixelToPointStringConverter}}" Height="25" MinHeight="25" Width="40" MinWidth="40" Background="Transparent" Margin="0 0 29 0" BorderBrush="Transparent" BorderThickness="0" />

Thanks again.

Cam



VM Venkatesan Mani Syncfusion Team February 6, 2017 04:26 AM UTC

Hi Cam, 
 
Thank you for you update. 
 
Please let us know if you require any further assistance. We will be happy to assist you.  
 
Regards, 
Venkatesan M. 


Loader.
Live Chat Icon For mobile
Up arrow icon