Set Line Spacing in RichTextEdit?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Set Line Spacing in RichTextEdit?

John Trinder
Does anybody know if it is possible to set the line spacing in either
RichTextEdit or TextEdit controls? If not is it possible to set line
spacing using, say, C++?


Reply | Threaded
Open this post in threaded view
|

Re: Set Line Spacing in RichTextEdit?

Christopher J. Demers
"John Trinder" <[hidden email]> wrote in message
news:[hidden email]...
> Does anybody know if it is possible to set the line spacing in either
> RichTextEdit or TextEdit controls? If not is it possible to set line
> spacing using, say, C++?

I don't know about the TextEdit control, but in a RichTextEdit you can set
the line spacing as part of the RTF text.  Either look up the RTF spec, or
just use an RTF capable Editor (Word, WordPad, Write, whatever...) set the
line spacing and save the file as RTF then look at the file.  Since Word
adds a lot of junk to an RTF file you may want to save it once with your
spacing, and once with default spacing to find the difference.

Chris


Reply | Threaded
Open this post in threaded view
|

Re: Set Line Spacing in RichTextEdit?

Ian Bartholomew-19
In reply to this post by John Trinder
John,

> Does anybody know if it is possible to set the line spacing in either
> RichTextEdit or TextEdit controls? If not is it possible to set line
> spacing using, say, C++?

The RichTextEdit sets the line spacing using the paragraph format
structure - PARAFORMAT2.  From the docs ...

=_=_=_=_=_=

dyLineSpacing
Spacing between lines. For a description of how this value is interpreted,
see the bLineSpacingRule member. To use this member, set the PFM_LINESPACING
flag in the dwMask member.

and

bLineSpacingRule
Type of line spacing. To use this member, set the PFM_SPACEAFTER**** flag in
the dwMask member. This member can be one of the following values.
  0
  Single spacing. The dyLineSpacing member is ignored.
  1
  One-and-a-half spacing. The dyLineSpacing member is ignored.
  2
  Double spacing. The dyLineSpacing member is ignored.
  3
  The dyLineSpacing member specifies the spacingfrom one line to the next,
in twips. However, if dyLineSpacing specifies a value that is less than
single spacing, the control displays single-spaced text.
  4
  The dyLineSpacing member specifies the spacing from one line to the next,
in twips. The control uses the exact spacing specified, even if
dyLineSpacing specifies a value that is less than single spacing.
  5
  The value of dyLineSpacing / 20 is the spacing, in lines, from one line to
the next. Thus, setting dyLineSpacing to 20 produces single-spaced text, 40
is double spaced, 60 is triple spaced, and so on.

=_=_=_=_=_=

**** That's wrong - it should say PFM_LINESPACING

The PARAFORMAT2 structure is not included in Dolphin (it contains the older
PARAFORMAT structure) but it is easy enough to implement.  It needs
RichEdit2 or later to work and I think that should be available on most
Windows systems.

To try it - save the following code (between the =_=s)  into a st file, file
it in and then evaluate this example in a workspace.  Anything you type
should be double spaced.

rte := RichTextEdit show.
pf2 := PARAFORMAT2 new.
pf2 dwMask: 256. "PFM_LINESPACING"
pf2 bLineSpacingRule: 2.  "double spaced"
rte setParaFormat2: pf2

#setParaFormat formats the current selection, or all new text from the
current position if there is no selection, so if you just want part of the
document formatted with different line spacing you will have to
select/deselect accordingly.

=_=_=_=_=_=

Win32Structure subclass: #PARAFORMAT2

instanceVariableNames: ''

classVariableNames: ''

poolDictionaries: ''

classInstanceVariableNames: ''!

PARAFORMAT2 guid: (GUID fromString:
'{4CB3134F-B24B-4D8E-BE73-FBBF98323875}')!

PARAFORMAT2 comment: ''!

!PARAFORMAT2 categoriesForClass!External-Data-Structured-Win32!IDB Goodies!
!

!PARAFORMAT2 class methodsFor!

defineFields

"typedef struct _paraformat {

UINT cbSize;

DWORD dwMask;

WORD wNumbering;

WORD wEffects;

LONG dxStartIndent;

LONG dxRightIndent;

LONG dxOffset;

WORD wAlignment;

SHORT cTabCount;

LONG rgxTabs[MAX_TAB_STOPS];

LONG dySpaceBefore;

LONG dySpaceAfter;

LONG dyLineSpacing;

SHORT sStyle;

BYTE bLineSpacingRule;

BYTE bOutlineLevel;

WORD wShadingWeight;

WORD wShadingStyle;

WORD wNumberingStart;

WORD wNumberingStyle;

WORD wNumberingTab;

WORD wBorderSpace;

WORD wBorderWidth;

WORD wBorders;

} PARAFORMAT2; "

self

defineField: #dwSize type: DWORDField writeOnly beOverride;

defineField: #dwMask type: DWORDField new;

defineField: #wNumbering type: WORDField new;

defineField: #wEffects type: WORDField new;

defineField: #dxStartIndent type: SDWORDField new;

defineField: #dxRightIndent type: SDWORDField new;

defineField: #dxOffset type: SDWORDField new;

defineField: #wAlignment type: WORDField new;

defineField: #cTabCount type: SWORDField new;

defineField: #rgxTabs type: (ArrayField type: DWORDArray length:
32 "MAX_TAB_STOPS");

defineField: #dySpaceBefore type: SDWORDField new;

defineField: #dySpaceAfter type: SDWORDField new;

defineField: #dyLineSpacing type: SDWORDField new;

defineField: #sStyle type: SWORDField new;

defineField: #bLineSpacingRule type: BYTEField new;

defineField: #bOutlineLevel type: BYTEField new;

defineField: #wShadingWeight type: WORDField new;

defineField: #wShadingStyle type: WORDField new;

defineField: #wNumberingStart type: WORDField new;

defineField: #wNumberingStyle type: WORDField new;

defineField: #wNumberingTab type: WORDField new;

defineField: #wBorderSpace type: WORDField new;

defineField: #wBorderWidth type: WORDField new;

defineField: #wBorders type: WORDField new! !

!PARAFORMAT2 class categoriesFor: #defineFields!initializing!public! !

!PARAFORMAT2 methodsFor!

dwSize: anObject

bytes dwordAtOffset: 0 put: anObject! !

!PARAFORMAT2 categoriesFor: #dwSize:!accessing!public! !

!RichTextEdit methodsFor!

setParaFormat2: aPARAFORMAT2

self

assert:

[(self

sendMessage: EM_SETPARAFORMAT

wParam: 0

lParam: aPARAFORMAT2 yourAddress) ~= 0]! !

!RichTextEdit categoriesFor: #setParaFormat2:!public! !

=_=_=_=_=_=

--
Ian

Use the Reply-To address to contact me.
Mail sent to the From address is ignored.


Reply | Threaded
Open this post in threaded view
|

Re: Set Line Spacing in RichTextEdit?

John Trinder
Amazing. I discovered PARAFORMAT2 struct on msdn after posting this,
and I knew that I'd have to analyse Dolphin's PARAFORMAT
implementation, but you seem to have provided all the necessary
groundwork for me to implement it. Cheers!


Reply | Threaded
Open this post in threaded view
|

Re: Set Line Spacing in RichTextEdit?

John Trinder
Ian,

This is a very late message, so I don't know if you'll read it.

I followed your instructions up to file in. I had to do PARAFORMAT2
class >> compileDefinitions, and after that your example code works
fine. Thankyou.

A small question: Does one have to enter a GUID every time a new
struct is implemented? Also, I've noticed that all classes have GUIDs
assiociated with them. Is this a Windows thing that Dolphin is
utilising? What are they for?

Again, thankyou and regards,

John


Reply | Threaded
Open this post in threaded view
|

Re: Set Line Spacing in RichTextEdit?

Chris Uppal-3
John Trinder wrote:

> A small question: Does one have to enter a GUID every time a new
> struct is implemented? Also, I've noticed that all classes have GUIDs
> assiociated with them. Is this a Windows thing that Dolphin is
> utilising? What are they for?

As far as I know, they are only used by the COM integration.  The system
defines a GUID for you whenever you create a new class.  I think the idea was
that they would be more generally useful sometime in the future, but I don't
know for what, and I don't know if that is still anticipated.

    -- chris


Reply | Threaded
Open this post in threaded view
|

Re: Set Line Spacing in RichTextEdit?

John Trinder
In reply to this post by John Trinder
Just a final question.

The message:

setParaFormat2: aPARAFORMAT2

self assert:
[(self
sendMessage: EM_SETPARAFORMAT
wParam: 0
lParam: aPARAFORMAT2 yourAddress) ~= 0]! !

What does this do and when does it get sent?

Regards, John


Reply | Threaded
Open this post in threaded view
|

Re: Set Line Spacing in RichTextEdit?

Andy Bower-3
In reply to this post by Chris Uppal-3
Chris,
 

> > A small question: Does one have to enter a GUID every time a new
> > struct is implemented? Also, I've noticed that all classes have
> > GUIDs assiociated with them. Is this a Windows thing that Dolphin is
> > utilising? What are they for?
>
> As far as I know, they are only used by the COM integration.  The
> system defines a GUID for you whenever you create a new class.  I
> think the idea was that they would be more generally useful sometime
> in the future, but I don't know for what, and I don't know if that is
> still anticipated.

Your guesses are correct!

Best regards

Andy Bower
Dolphin Support
www.object-arts.com


Reply | Threaded
Open this post in threaded view
|

Re: Set Line Spacing in RichTextEdit?

Ian Bartholomew-19
In reply to this post by John Trinder
John,

> setParaFormat2: aPARAFORMAT2
[snip]
> What does this do and when does it get sent?

In the original example I posted it was used in the test code at the top of
the message.  You need to use it whenver you need to change one of the
formatting options defined in PARAFORMAT2.  The base Dolphin system only
uses the PARAFORMAT structure (a RichTextEdit will accept either PARAFORMAT
or PARAFORMAT2) so you will need to add, and call, the setParaFormat2:
method if you want to, for example, change the line spacing.

To use it you just create a new PARAFORMAT2 structure, set its mask value to
indicate which parameters you are changing, set the values that you want to
alter and pass the structure to the RichTextEdit control.

HTH

--
Ian

Use the Reply-To address to contact me.
Mail sent to the From address is ignored.