PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sat Apr 27, 2024 6:52 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Fri Jan 29, 2010 3:32 am 
Offline

Joined: Fri Oct 24, 2008 12:24 pm
Posts: 13
Location: Brisbane, Australia
When adding a style it appears that the Font information is not being inherited from the base style specified. I have the following code
Code:
var normalStyle = document.Styles["Normal"];
normalStyle.Font.Name = "Calibri";
var tableStyle = document.Styles.AddStyle("Table", "Normal");

If I set a breakpoint after this code and enter the following commands in the "Immediate Window" to inspect the results it is clear (from the responses in bold) that the Font information is not being inherited as expected

? document.Styles["Normal"].Font.Name
"Calibri"
? document.Styles["Table"].Font.Name
""


similarly (obviously) the font sizing infomation is not being inherited either.

Am I misunderstanding the concept of how the inhertance in styles works?


Top
 Profile  
Reply with quote  
PostPosted: Fri Jan 29, 2010 4:06 am 
Offline

Joined: Fri Oct 24, 2008 12:24 pm
Posts: 13
Location: Brisbane, Australia
.... having looked into the Styles.cs file myself I think there may be an issue at the end of the method public override void Add(DocumentObject value) that clones and inserts the new style into the Styles collection

the following changes fix my initial observations

Code:
public override void Add(DocumentObject value)
{
      :
      :
      if (baseStyle != null)
      {                                                        // inserted
          string originalName = style.name.Value;              // inserted
          string originalBaseStyleName= style.baseStyle.Value; // inserted
          style = baseStyle.Clone();                           // inserted
          style.name.Value = originalName;                     // inserted
          style.baseStyle.Value = originalBaseStyleName;       // inserted
          // style.styleType.Value = (int)baseStyle.Type;      // removed
      }                                                        // inserted
     
      int index = GetIndex(style.Name);

      if (index >= 0)
      {
        style = style.Clone();
        style.parent = this;
        ((IList)this)[index] = style;
      }
      else
        base.Add(style);                                      // changed
}


and finally in the method public Style AddStyle(string name, string baseStyleName) the final line should return the style just inserted (which may have changed:

Code:
public Style AddStyle(string name, string baseStyleName)
{
    :
    :
    return this[name];                                  // changed
}


however you have the test suite (!) so that probably buggers up a whole manner of other things!

I'd be interested to know whether the above is indeed the correct workaround or whether I am barking up the wrong tree entirely :lol:


Top
 Profile  
Reply with quote  
PostPosted: Mon Feb 01, 2010 12:55 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
Orestone wrote:
Am I misunderstanding the concept of how the inhertance in styles works?

I'm not sure, but I think you misunderstood the concept.

If the tables are rendered with Calibri (and that's what I expect), then everything is working as it should.

If you change "Normal" to Verdana later in the program, tables will also be rendered with Verdana. That's not a bug, that's a feature.
With your change, tables would still be rendered with Calibri as the font name was copied when the style was created.

Only drawback: you don't see the inherited values in the debugger.

I check my styles by looking at the PDF file and the MDDDL file:
http://www.pdfsharp.net/wiki/MigraDocDDL.ashx?HL=mdddl

_________________
Regards
Thomas Hoevel
PDFsharp Team


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

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 390 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