Skip to main content

Hi all,

Any ideas?  How might I call out from Visual COBOL (Windows environment) to measure the height of a given piece of text rendered with a given font, point size, column width? 

e.g. A call to calculate the size of this text in Arial 12 point in 50mm width column, "FORD FOR SALE. Lovely condition, very economical, £30 road tax, low insurance. MOT to August 2018 with no advisories. Cambelt Water Pump and Coolant all changed in August 2017. Continental tyres with plenty of tread all round. Ford Radio CD with auxiliary port for I Phone MP3 etc. Owned by us since May 2011."

Anyone done this from COBOL?  Any ideas appreciated.

Thanks,

Linden

Hi all,

Any ideas?  How might I call out from Visual COBOL (Windows environment) to measure the height of a given piece of text rendered with a given font, point size, column width? 

e.g. A call to calculate the size of this text in Arial 12 point in 50mm width column, "FORD FOR SALE. Lovely condition, very economical, £30 road tax, low insurance. MOT to August 2018 with no advisories. Cambelt Water Pump and Coolant all changed in August 2017. Continental tyres with plenty of tread all round. Ford Radio CD with auxiliary port for I Phone MP3 etc. Owned by us since May 2011."

Anyone done this from COBOL?  Any ideas appreciated.

Thanks,

Linden

Hi Linden -

The logic to figure this out requires you to understand win32 calling conventions and you have access to a window's device context and the ability to select a font into that context. If you are familiar with that look into the DrawText command and the DT_CALCRECT option:

msdn.microsoft.com/.../dd162498(v=vs.85).aspx

Cheers!
Greg

Hi all,

Any ideas?  How might I call out from Visual COBOL (Windows environment) to measure the height of a given piece of text rendered with a given font, point size, column width? 

e.g. A call to calculate the size of this text in Arial 12 point in 50mm width column, "FORD FOR SALE. Lovely condition, very economical, £30 road tax, low insurance. MOT to August 2018 with no advisories. Cambelt Water Pump and Coolant all changed in August 2017. Continental tyres with plenty of tread all round. Ford Radio CD with auxiliary port for I Phone MP3 etc. Owned by us since May 2011."

Anyone done this from COBOL?  Any ideas appreciated.

Thanks,

Linden

Thank you Greg, very useful. I have enough knowledge of api calls to give this a go.
Much appreciated,
Linden

Hi all,

Any ideas?  How might I call out from Visual COBOL (Windows environment) to measure the height of a given piece of text rendered with a given font, point size, column width? 

e.g. A call to calculate the size of this text in Arial 12 point in 50mm width column, "FORD FOR SALE. Lovely condition, very economical, £30 road tax, low insurance. MOT to August 2018 with no advisories. Cambelt Water Pump and Coolant all changed in August 2017. Continental tyres with plenty of tread all round. Ford Radio CD with auxiliary port for I Phone MP3 etc. Owned by us since May 2011."

Anyone done this from COBOL?  Any ideas appreciated.

Thanks,

Linden

MY SOLUTION:
I've solved this by using MF's old invoke font class gui library, "ObjectTextExtent" method. Works really well. By looping around measuring each word I can handle font and style changes mid text and work out where line breaks are needed. The font methods return widths in logical pixels (96 per inch) which I can easily translate to mm.
The only problem I have now is that the target InDesign/Quark software will hyphenate to break long words across lines. However hyphenation is a minor concern in reality and only makes a difference if the text is shunted up a whole line at the bottom.
Happy to share my code if anyone interested.