WPCubed Product Support

Paragraph styles

I'm defining a couple of styles in code :-

aStyle := Editor.ParStyles.AddStyle(STYLE_PLAIN);   aStyle.ASetFontName('Verdana');   aStyle.ASet(WPAT_CharFontSize, 15*100); // 15pt   aStyle := ditor.ParStyles.AddStyle(STYLE_QUOTED);   aStyle.ASetFontName('Lucida Console');   aStyle.ASet(WPAT_CharFontSize, 14*100); // 14pt

I then try to set STYLE_PLAIN as the active style

Editor.ActiveStyleName := STYLE_PLAIN

But the text is rendered using the font and size from CurrAttr which is 11pt Arial. I've tried setting Editor.CurrAttr.StyleName to STYLE_PLAIN as well, but that makes no difference.

What am I missing?

Here's what the saved text looks like in WPT format (I've just taken the bit from the end)

<stylesheet><pstyle name="Plain" nr=1 wpsty=[[CharFont:'Verdana';CharFontSize:1500;CharStyleMask:7;CharBGColor:clWhite;]]/>
<pstyle name="Quoted" nr=2 wpsty=[[CharFont:'Lucida Console';CharFontSize:1400;CharStyleMask:7;CharColor:clGreen;CharBGColor:clWhite;]]/>
</stylesheet><div><cs nr=1 wpsty=[[CharFont:'Arial';CharFontSize:1100;]]/><c nr=1/>Testing lkfj sldjf lsdjflsdljsd lksdlkf jlsjfd</div>
#1 ✎ ♥ 0
15.9k Views 1 links 2 users read 4 min
support

Hi,

probably the current font uses the character attributes you see. WPTools will use only those attributes of styles which are not used in an element at higher level.

So you need to clear those attributes. You can use

CurrAttr.ClearAttributes

with WPRichText1.ParStyle.GetID(STYLE_PLAIN ) as parameter.

BTW.: Please avoid headlines like this.

Julian

#2 ♥ 0

Thanks, I'll give that a try.

I've amended the headline.

#3 ♥ 0

No, that didn't work.

Tracing through there is no change whatsoever to CurrAttr.FontName or CurrAttr.Size.

Here's the code :-

Editor.ActiveStyleName := STYLE_PLAIN;
		Editor.CurrAttr.StyleName := STYLE_PLAIN ;
		Editor.CurrAttr.ClearAttributes(-1) ;
		Editor.CurrAttr.StyleName := STYLE_PLAIN ;

I changed it to use ClearAttributes(-1) since Editor.ParStyles.GetId(STYLE_PLAIN) didn't work either.

Any other suggestions?

I'll try to create a small example program that shows the same problem if that would help.

#4 ♥ 0
support

Hi,

this code is executed inside WPCTRRich for the style name combobox ()or action)

wptTyp:        begin           if (str='') or (str=WPLoadStr(meUndefinedStyle)) then                CurrAttr.StyleName := ''           else if str=WPLoadStr(meEditCurrStyle) then                OpenDialog(wpdiaEditCurrentStyle)           else if str=WPLoadStr(meCreateNewStyle) then                OpenDialog(wpdiaCreateNewStyle)           else CurrAttr.StyleName := str;        end;

It seems to always work. ActiveStyleName is just the same as 'CurrAttr.StyleName'.

This is the code executed for ActiveStyleName. It is interesting because of the use of the 'TextCursor' property which is responsible for all the trext changes. CurrAttr is more or less only provided for compatibility reasons, although there is no need to NOT use it - except for server procedures wher I recommend to create a TWPCusomtRTFEdit in code.

procedure TWPCustomRtfEdit.SetActiveStyleName(const x: string);
var sty: TWPRTFStyleElement;
  i: Integer;
  Cursor: TWPRTFDataCursor;
begin
  Cursor := TextCursor;
  if x <> '' then
    sty := Cursor.RTFProps.ParStyles.Add(x)
  else sty := nil;
  if sty <> nil then i := sty.ID else i := 0;
  if Cursor.IsSelected then
  begin
    Cursor.SelectedTextAttr.SetStyle(i, wpClearAttrOnStyleChange in EditOptions, wpClearAttrOnStyleChange in EditOptions);
  end
  else
  begin
    Cursor.WritingTextAttr.SetStyle(i, wpClearAttrOnStyleChange in EditOptions, wpClearAttrOnStyleChange in EditOptions);
  end;
end;

In your case - is actually a selection defined?

Otherwise you can also use ActivaParagraph.ASetBaseStyle

Julian

#5 ♥ 0

In this case there is no text at all, this is on opening the window.

I've done a simple example that demonstrates the problem, where do I send it?

#6 ♥ 0
support

Hi,

if there is no text then the editor is empty. In WPTools 5 the editor is really empty, there is even no empty paragraph.

Use WPRichText.CheckHasBody; to create an empty body.

Julian

#7 ♥ 0

Makes no difference I'm afraid - where do I send my example?

#8 ♥ 0
support

Hi,

Makes no difference I'm afraid - where do I send my example?

Juliaj Ziersch

#9 ♥ 0

You should have the sample project by now.

#10 ♥ 0

Thanks Julian, that helps, but it only seems to apply to the first paragraph.

As soon as I hit enter I'm back to 11pt Arial for the next paragraph!

#12 ♥ 0
support

Hi,

This should not be this way - I check that. GetCharAttr is called too often.

Julian

#13 ♥ 0

Any luck with this?

I have a workaround, which is to check the current paragraph style in the OnChanged event and to set it if it is empty. It works but it's quite nasty.

#14 ♥ 0
This category is archived. No new posts are possible.