Grid2Print - Suggestions

Source code related resources

Moderator: Rathinagiri

User avatar
Rathinagiri
Posts: 5166
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 129 times
Been thanked: 131 times
Contact:

Grid2Print - Suggestions

Post by Rathinagiri » Mon Aug 04, 2008 5:57 pm

The latest version of Grid2Print can be downloaded from here.


I use MySQL as my back end database and HMG as front end GUI.

Whenever I raise a SQL query, I populate the results in a grid and if the user wants to print the data, I call a small module called Grid2Print. With the new Harbour RC I am planning to extend this feature to PDF also.

Now, I am showing the screenshot and the module syntax for you. Give me any suggestions that may come to your mind and as Roberto told, we can have a generic method to print a grid.

This is the screenshot of my module now.

Image

The syntax is as follows:

Code: Select all

Grid2Print(cGridName,cWindowName,aHeaders,aSizes,aTypes,cHeader1,cHeader2,cHeader3,nFontsize,cOrientation,lShowWindow)
Explanation:

cGridName : Name of the Grid control
cWindowName: Name of the parent window
aHeaders : Headers of each column in the grid in an array of characters. (Is there anyway to retrieve the headers of a grid?)
aSizes : Sizes of each columns (Here too width of the columns we can't retrieve as a property. This can be changed before printing as the user desires)
aTypes : Type of each column as a single character array (e.g.: {"C","N","D","L"}
cHeader1..3 : Some headers for the report. :)
nFontsize: Basic Fontsize through out the report
cOrientation: either "P" for portrait or "L" for Landscape
lShowWindow: Logical value whether or not to show the above window to the user while runtime. If selected .f., this window is not shown and with default values, grid data is directly given to the HMG printer module and preview is shown.

Some points:

1. Total width of the paper (in mm) is converted into number of columns by an average formula which uses the fontsize in points (72 points per inch). However, the width of each character is not fixed and in hbvpdf library I had seen a function to calculate this. So, I am working on that. If anybody have already worked on that please throw some light on this.

2. Some columns can be eliminated by the user himself (as mentioned as X) by double clicking the column name.

3. Only when the total width to be printed is less than the total width available, the print button is enabled.

4. The size of the column can be changed by clicking the edit button after selecting the corresponding column name.

5. Lengthy lines can be either truncated or word wrapped.

To be implemented:

1. Now I have a fixed margin of 20 mm from all the sides. This can be made user definable.

2. I had selected Arial as the default font. This too can be given to the user's option.

3. Instead of column size in number of characters, I plan to make it as given in millimeters.

Now, I am just awaiting for your replies. :)
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.

User avatar
Roberto Lopez
HMG Founder
Posts: 3899
Joined: Wed Jul 30, 2008 6:43 pm
Has thanked: 13 times
Been thanked: 135 times

Post by Roberto Lopez » Mon Aug 04, 2008 8:26 pm

It looks very good!

But.... I have a question... :)

Could be possible to test column types automatically instead of request the user to add in the function call?

This will be consistent with (ie) Browse that detect field types automatically.

Regards,

Roberto.
Regards/Saludos,

Roberto


(Veritas Filia Temporis)

User avatar
Roberto Lopez
HMG Founder
Posts: 3899
Joined: Wed Jul 30, 2008 6:43 pm
Has thanked: 13 times
Been thanked: 135 times

Post by Roberto Lopez » Mon Aug 04, 2008 9:00 pm

And....

Maybe... instead of have 3 parameters for three possible headers, you could use an unique parameter (acHeaders). An array of strings (one element for each desired header).

IMHO this will make the syntax simpler (two parameters less) and gives to the function more flexibility.

Regards,

Roberto.
Regards/Saludos,

Roberto


(Veritas Filia Temporis)

User avatar
Rathinagiri
Posts: 5166
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 129 times
Been thanked: 131 times
Contact:

Post by Rathinagiri » Mon Aug 04, 2008 9:14 pm

Yes, Roberto. I thought that too.

And, if we can get the headers (of the columns in the grid) property as defined and widths property as defined, further two parameters would get reduced. And on getting this, I can divide the total width according to the width of each column of the grid and give to the user for modification if any.

After that the total syntax would be,

Grid2Print(cGridName,cWindowName,aHeaders,nFontsize,cOrientation,lShowWindow)

:)
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.

User avatar
Roberto Lopez
HMG Founder
Posts: 3899
Joined: Wed Jul 30, 2008 6:43 pm
Has thanked: 13 times
Been thanked: 135 times

Post by Roberto Lopez » Tue Aug 05, 2008 1:13 am

rathinagiri wrote:Yes, Roberto. I thought that too.

And, if we can get the headers (of the columns in the grid) property as defined and widths property as defined, further two parameters would get reduced. And on getting this, I can divide the total width according to the width of each column of the grid and give to the user for modification if any.

After that the total syntax would be,

Grid2Print(cGridName,cWindowName,aHeaders,nFontsize,cOrientation,lShowWindow)

:)
Making this generic could be a true nightmare :)
But, we can think about solutions...

These are only ramdon ideas... (maybe not all of these good:)

We could sum the widths of all columns and obtain the total width, then the percentage of total width that uses each column and scale to paper width. Of course, this is another problem :)

So... paper size should be another parameter ?

And printer name ?

Or... printer selection dialog?

What about output type (printer or PDF) ?

Global sets for these parameters?

Reasonable defaults for these, that the user could change via optional parameters?

If anybody has something to say... I'm listening....

Regards,

Roberto.
Regards/Saludos,

Roberto


(Veritas Filia Temporis)

User avatar
Rathinagiri
Posts: 5166
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 129 times
Been thanked: 131 times
Contact:

Post by Rathinagiri » Tue Aug 05, 2008 4:44 am

We could sum the widths of all columns and obtain the total width, then the percentage of total width that uses each column and scale to paper width. Of course, this is another problem
This is what I too had emphasized. Thank you Roberto.

As you said, paper size parameter is required. Regarding Printer selection, I think default printer can be selected. If the user wants he can select any other available printer.

Regarding PDF, we can have a button exclusively for that in this dialog.

So, all put together, the last parameter lShowWindow can be removed and the window can be shown always. ;)

Shall I proceed with the alterations?
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.

User avatar
Roberto Lopez
HMG Founder
Posts: 3899
Joined: Wed Jul 30, 2008 6:43 pm
Has thanked: 13 times
Been thanked: 135 times

Post by Roberto Lopez » Tue Aug 05, 2008 12:29 pm

rathinagiri wrote:
We could sum the widths of all columns and obtain the total width, then the percentage of total width that uses each column and scale to paper width. Of course, this is another problem
So, all put together, the last parameter lShowWindow can be removed and the window can be shown always. ;)
Shall I proceed with the alterations?
As I've said, were some just random ideas to try to simplify the HMG programmer life :)

In my experience the final user only wants the things running as quick and simple as possible.

So, IMHO the configuration dialog must be optional and the choice to set all from parameters must be available, but as optional ones, preselecting reasonable defaults.

Regards,

Roberto.
Regards/Saludos,

Roberto


(Veritas Filia Temporis)

User avatar
Rathinagiri
Posts: 5166
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 129 times
Been thanked: 131 times
Contact:

Post by Rathinagiri » Tue Aug 05, 2008 1:01 pm

Ok Roberto. Thanks for your valuable guidance.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.

User avatar
Rathinagiri
Posts: 5166
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 129 times
Been thanked: 131 times
Contact:

Post by Rathinagiri » Wed Aug 13, 2008 8:10 am

Is there any way to find out the advancement width of a character/string in mm while printing with variable width fonts?

Like stringwidth() in other languages.

I wish to have a function which returns the width of a given string in millimeters with the given font name and font size.

I think GetCharWidthFloat() in C API deals with it. Can it be used/implemented in HMG?

Please help me out.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.

User avatar
Rathinagiri
Posts: 5166
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 129 times
Been thanked: 131 times
Contact:

Post by Rathinagiri » Wed Aug 13, 2008 10:34 am

With a small research I found we have gettextwidth(Nil,cString,cFontname) in HMG which returns the width of a given string in the specified font in terms of logical units. Can we convert this units into printer points according to the size of the font?
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.

Post Reply