PDFsharp & MigraDoc Foundation https://forum.pdfsharp.net/ |
|
AddStyle not inheriting Font information? https://forum.pdfsharp.net/viewtopic.php?f=2&t=1037 |
Page 1 of 1 |
Author: | Orestone [ Fri Jan 29, 2010 3:32 am ] |
Post subject: | AddStyle not inheriting Font information? |
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? |
Author: | Orestone [ Fri Jan 29, 2010 4:06 am ] |
Post subject: | Re: AddStyle not inheriting Font information? |
.... 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 ![]() |
Author: | Thomas Hoevel [ Mon Feb 01, 2010 12:55 pm ] |
Post subject: | Re: AddStyle not inheriting Font information? |
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 |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |