PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Tue Apr 23, 2024 11:53 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Tue Aug 02, 2016 8:48 pm 
Offline

Joined: Tue Jul 26, 2016 5:07 pm
Posts: 32
The following code applies the styles configuration persisted somewhere (database, file etc).
It is called in a loop for every style persisted that way: both built-in and user-defined styles.
The variable 'q' here is a dynamic object representing the table fields of one record.
This works exactly as described in the examples for the built-in styles as you can see in the attachment: the Heading2 is correct size.
Code:
Style style = document.Styles[q.StyleCode] ?? document.Styles.AddStyle(q.StyleCode, q.BasedOn);
style.BaseStyle = q.BasedOn ?? style.BaseStyle;
style.Font.Name = q.FontName ?? style.Font.Name;
style.Font.Size = q.FontSize ?? style.Font.Size;
style.Font.Bold = q.FontBold ?? style.Font.Bold;
style.Font.Italic = q.FontItalic ?? style.Font.Italic;
style.ParagraphFormat.PageBreakBefore = q.PageBreakBefore ?? false;
style.ParagraphFormat.SpaceBefore = q.SpaceBefore ?? style.ParagraphFormat.SpaceBefore;
style.ParagraphFormat.SpaceAfter = q.SpaceAfter ?? style.ParagraphFormat.SpaceAfter;
style.ParagraphFormat.LeftIndent = q.LeftIndent ?? style.ParagraphFormat.LeftIndent;
style.ParagraphFormat.RightIndent = q.RightIndent ?? style.ParagraphFormat.RightIndent;
style.ParagraphFormat.FirstLineIndent = q.FirstLineIndent ?? style.ParagraphFormat.FirstLineIndent;

When I supply Normal for BasedOn and no FontSize, I expect the font of the paragraphs added w/o specifying any style to be the same size as of the paragraphs added with a style based on Normal which has some other parameters set (in my case those are LeftIndent and FirstLineIndent).

But the font size is different: it is smaller for the unspecified style (yellow highlighter in the attached) and larger for my new style based on Normal (circled in red in the attachment).

What am I doing wrong?


Attachments:
Capture.JPG
Capture.JPG [ 21.16 KiB | Viewed 5285 times ]
Top
 Profile  
Reply with quote  
PostPosted: Wed Aug 03, 2016 6:10 am 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 916
Location: CCAA
Hi1
vorobej wrote:
What am I doing wrong?
Properties are inherited - until you assign a value.

vorobej wrote:
style.Font.Size = q.FontSize ?? style.Font.Size;
This code assigns a value, even if "q.FontSize" is null. After this line the font size is no longer inherited and later changes to "Normal" will not work.
An "if(q.FontSize != null)" would make a difference here.

vorobej wrote:
What am I doing wrong?
You only show a code snippet. How can I know what is really going on and what is going wrong?

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
PostPosted: Wed Aug 03, 2016 4:20 pm 
Offline

Joined: Tue Jul 26, 2016 5:07 pm
Posts: 32
I am using 1.5.4000 beta 3 if that matters.

The corresponding section of MDDDL is not showing any font size applied:

Code:
    UWQuestionAnswer : Normal
    {
      ParagraphFormat
      {
        LeftIndent = "3.5cm"
        FirstLineIndent = "-2.5cm"
      }
    }


And the paragraphs are not showing any font size either:

Code:
    \paragraph
    [
      Style = "UWQuestionAnswer"
    ]
    {
      Question 1:\tab What is your height?
    }
    \paragraph
    [
      Style = "UWQuestionAnswer"
      Format
      {
        SpaceBefore = 0
        SpaceAfter = 8
      }
    ]
    {
      Response 1:\tab 1.8
    }
    \paragraph
    [
      Style = "UWQuestionAnswer"
    ]
    {
      Question 2:\tab What is your weight?
    }
    \paragraph
    [
      Style = "UWQuestionAnswer"
      Format
      {
        SpaceBefore = 0
        SpaceAfter = 8
      }
    ]
    {
      Response 2:\tab 70
    }


So my thinking was that the font size should be inherited from Normal which is 9, but these are showing in size 10.


Top
 Profile  
Reply with quote  
PostPosted: Wed Aug 03, 2016 4:29 pm 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 916
Location: CCAA
vorobej wrote:
So my thinking was that the font size should be inherited from Normal which is 9, but these are showing in size 10.
Sounds plausible.

But with the current code snippets and MDDDL snippets I don't have enough information to understand or replicate the problem.

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 191 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group