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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

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

Thread ID:

Created:

Updated:

Platform:

Replies:

128666 Feb 3,2017 11:01 AM Feb 5,2017 11:26 PM UWP 3
loading
Tags: SfRichTextBoxAdv
Cam Stevenson
Asked On February 3, 2017 11:01 AM

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

Venkatesan Mani [Syncfusion]
Replied On February 4, 2017 02:12 AM

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. 


Cam Stevenson
Replied On February 4, 2017 10:05 AM

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


Venkatesan Mani [Syncfusion]
Replied On February 5, 2017 11:26 PM

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. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;