Hi,
I need to create a report with a justified text (as if it was made with Word).
I used the TEXT control on the report.
The text is dynamically created with the content of several fields.
How can be done?
Clarion 11.1 EE
TIA!
Hi,
I need to create a report with a justified text (as if it was made with Word).
I used the TEXT control on the report.
The text is dynamically created with the content of several fields.
How can be done?
Clarion 11.1 EE
TIA!
Can you define what you mean by āJustifyā? I assume you do not mean left or right justified ![]()
Are you talking about āfullā?
Hi,
Thanks for your reply!
Yes, Iām refering to full justify alignment, not left or right alignment.
Iām trying to directly print a contract, filled with the contractors data, calling a REPORT with a TEXT control and using a STRING variable with the full text.
There isnāt any formatting in the text (bold, italic, etc.), so no need to have a RTF control on a WINDOW before printing. Just plain text to print.
But I need the text to have full justified alignmentā¦
I saw the RTF NotePad in the examples folder and could be a great solution. But Iām seeking something simplerā¦
You can use CENTER but Iām thinking you want the text evenly spread across the width, ie: increasing the space between words. Iām uncertain if thatās easily possible using Clarion without some add-on.
Hi,
Yes. This is exactly what I wantā¦
Looking at the RTF NotePad example gave me some ideas about a posible solution using a hidden RTFTextControl control template and the RTFAction code templateā¦
But Iād still prefer a simpler solution⦠![]()
If you have a non-proportional font it makes this a lot easier, otherwise itās a PITB. Iāve done similar, by using a separate hidden TEXT control to test the actual width. It might be simplest to do a string theory Split() to separate the words into a queue, but maybe not the most efficient way.
First you need to determine the number of spaces that you need to make up the width that you need to make the line āfullā, using your particular font, etc.
Then divide that number of spaces into a separator string that can be used to re-join the split() string theory object.
Have a look at st.wrapText
It will get you around 75% there and leaves the lines in the lines queue
Then take each lIne in another st object and split on space. Pad as desired then rejoin and move back into the original line.
I am just on my phone boarding a plane but hopefully that gives you an idea. A few considerations when padding a line:
Only one word on line then left justify.
Only two words then left justify the first and right justify the second.
See how you go. I can help more from my destination!
Cheers
Geoff R
OK I have arrived and consumed some duty free Irish whisky to lubricate the synapses (so this is guaranteed to work first time, ha ha) and I am thinking maybe something like:
AlignText procedure(stringTheory pSt, long pWidth=80, bool pKeepExistingBreaks=true, bool pleft=false)
lne stringTheory
x long,auto
y long,auto
extraSpaces long,auto ! how many spaces we need to pad
appendSize long,auto ! number of extra chars between each and every word
remainder long,auto ! number of extra word gaps to be expanded
code
pSt.wrapText(pWidth, pKeepExistingBreaks, pleft)
loop x = 1 to pSt.records()
lne.setValue(pSt.getLine(x))
extraSpaces = pWidth - lne.len()
if extraSpaces < 1 then cycle. ! no need to expand
lne.split(' ')
if lne.records() = 1 then cycle. ! only one word on line
appendSize = extraSpaces / (lne.records() - 1)
remainder = extraSpaces % (lne.records() - 1)
loop y = lne.records()-1 to 1 by -1
if appendSize = 0 and remainder = 0 then break.
lne.setValueFromLine(y)
if remainder > 0
lne.adjustLength(appendSize + 1)
remainder -= 1
else
lne.adjustLength(appendSize)
end
lne.setLineFromValue(y)
end
lne.join(' ')
? assert(lne.len() = pWidth) ! are we good?
pSt.setLine(x, lne) ! replace expanded line
end
pSt.join('<13,10>') ! combine updated lines
let us know how you go or if you need any explanation
cheers again
Geoff R
Hi, guys
Thank you all for the answers.
Iām trying some ideas taken from the RTF NotePad example, as my need is sort of a simplified mail merge.
Iāll let you know my progress.
Thank you again!
If you can swing it with RTF, thatās probably your best option. Padding with spaces in a plain TEXT control, unless you use a fixed font, will never look perfect.
Yes.
I already have the text as a Word document and saved it as a RTF document.
Based on the RTF NotePad example, Iām thinking to use the RTFControlClass to load the file into a TEXT control and use the Search and Replace method to merge the text with the contractors data.
But not today, as Iāve spent my whole day in meetingsā¦
Tomorrow will be a better day⦠![]()
Hi, guys
Itās finally working!
After several trial and errors to learn the right way, it is really simple! ![]()
As I said, I already had the original Word file with full justified text. I just created some tokens to be replaced with the real data and saved the file as a RTF file. The same use case of the mail merge of the RTF NotePad example on Clarion.
As I need to replace some text, Iāll also need to use the RTFControlClass.
The simple steps:
INCLUDE('rtfctl.inc'),ONCE
LOC:RTFFileName CSTRING('MyFile.RTF<0>{240}')
LOC:RTFText CSTRING(5001)
RTFControl CLASS(RTFControlClass)
END
detail DETAIL,AT(0,0),USE(?detail)
TEXT,AT(365,0,7208,896),USE(LOC:RTFText),RTF(TEXT:Field),BOXED,RESIZE,TRN
END
ThisWindow.OpenReport PROCEDURE
! Parent Call
ReturnValue = PARENT.OpenReport()
! [Priority 5001]
SETTARGET(Report) ; RTFControl.Init( ?LOC:RTFText) ; SETTARGET()
ThisReport.TakeRecord PROCEDURE
! Parent Call
ReturnValue = PARENT.TakeRecord()
! [Priority 5500]
DO ReplaceText
PRINT(RPT:Detail)
ReplaceText ROUTINE
RTFControl.Load( LOC:RTFFileName)
RTFControl.FindAndReplace( 'Token1', CLIP( LEFT( CUS:Name)))
RTFControl.FindAndReplace( 'Token2', CLIP( LEFT( CUS:Address)))
SETTARGET(Report)
UPDATE(?LOC:RTFText)
SETTARGET()
detail2 DETAIL,AT(0,0),USE(?DETAIL2)
TEXT,AT(365,0,7208,896),USE(LOC:RTFFileName),RTF(TEXT:File),BOXED,RESIZE,TRN
END
Hope this could help someone.
Thank you, guys!
Best regards.