1. Miguel Leeuwe
  2. PowerBuilder
  3. Tuesday, 28 January 2020 13:48 PM UTC

Hi,

I'm listing all fonts installed on a pc in a dropdown.

If a user chooses a font, I want to apply that to a dw column.

To do so, I need to set the "font.face" and the "font.family" (values 0 - 6, "Modern", "DontCare", "Roman", "Swiss", etc.) with a Modify() statement. (not sure if pb handles the "DontCare" value).

I'm getting the list of font names (for the "font.face" attribute), using C#, but I haven't figured out how to determine the font.family, given the name of a font.face.

So in short:

How do I get the font.family value for let's say "Arial" ?

Is there an API or do I oversee something in C#?

In C# I do something like this (see code below), but the fontFamilies[j].Name corresponds to what we need for font.facename that we need in PB. I don't see how to get the other value I need:

Anyone?

 

public void GetFontList()
        {
            //string fontName = "", fontFamily = "";
            //string fontList = "";
            //for each(fontName in fonts.)
            //foreach (FontFamily font_family in fonts.Families)
            //{
            //    // lstFonts.Items.Add(font_family.Name);
            //    fontFamily = font_family.Name;
            //    fontName = font_family.
            //    //fontList +=
            //}
            //return fontList;

            FontFamily fontFamily = new FontFamily("Arial");
            Font font = new Font(
               fontFamily,
               8,
               FontStyle.Regular,
               GraphicsUnit.Point);

            string familyName;
            string familyList = "";
            FontFamily[] fontFamilies;

            InstalledFontCollection installedFontCollection = new InstalledFontCollection();

            // Get the array of FontFamily objects.
            fontFamilies = installedFontCollection.Families;

            // The loop below creates a large string that is a comma-separated
            // list of all font family names.

            int count = fontFamilies.Length;
            int familyFamily;
            // string sFamilyFamily = "";
            for (int j = 0; j < count; ++j)
            {
                familyName = fontFamilies[j].Name;

                //switch (familyFamily)
                //{
                //    case 0:
                //        sFamilyFamily = "";
                //        break;
                //    case 1:
                //        sFamilyFamily = "";
                //        break;
                //    case 2:
                //        sFamilyFamily = "";
                //        break;
                //    case 3:
                //        sFamilyFamily = "";
                //        break;
                //    case 4:
                //        sFamilyFamily = "";
                //        break;
                //    case 5:
                //        sFamilyFamily = "";
                //        break;
                //    default:
                //        sFamilyFamily = "[Unknown]";
                //        break;
                //}

                //familyList += (familyName + " [@@] " + sFamilyFamily + "\r\n" );
            }
        }
Accepted Answer
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Wednesday, 5 February 2020 02:01 AM UTC
  2. PowerBuilder
  3. # Permalink

Previously attached sample app was in a bad state. I have improved things by using a nonvisual object.

See attached.

Attachments (1)
Comment
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Tuesday, 4 February 2020 10:23 AM UTC
  2. PowerBuilder
  3. # 1

It's taken a while, sorry very busy, but here's my adapted version of Eric Alding's sample, modified to work on a text object in a datawindow, instead of on a text control and also applying as much of the possible attributes.

See attached zip file.

Might be of any use to anyone.

Pending: Modify all the API external function declarations to NOT use the ;Ansi 'A' versions.  I gave it an initial shot, but things then blew up, so would need some more time.

Attachments (1)
Comment
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Wednesday, 29 January 2020 07:39 AM UTC
  2. PowerBuilder
  3. # 2

Added info:

Eric's sample does not apply any of the following, which I need for dw columns / labels:

- font.strikethrough

- font.family

- font.pitch

It's a bit tricky to get the last 2 but I think I've managed to do so:

There's a value in the returned structure called "PitchAndFamily", reading up on this, I found that the lower 2 bits would represent the pitch and "bits 4-7" would be the Family. I'm not too sure what that last one means. If anyone has a better knowledge of how to do this, feel free to correct my code.

Looking at this page: https://docs.microsoft.com/en-us/previous-versions/windows/desktop/bb322837(v=vs.85), I learned this information:

Members

Member Value Description
FamilyDecorative 80 Specifies a novelty font; for example, Old English.
FamilyScript 64 Specifies a font that is designed to look like handwriting; for example, Script and Cursive.
FamilyModern 48 Specifies a monospace font with or without serifs. Monospace fonts are usually modern; examples include Pica, Elite, and Courier New.
FamilySwiss 32 Specifies a proportional font without serifs; for example, Arial.
FamilyRoman 16 Specifies a proportional font with serifs; for example, Times New Roman.
FamilyDoNotCare 0 Specifies a generic family name, which is used when information about a font does not exist or does not matter. The default font is used.
MonoFont 8 Specifies a monospace font.
VariablePitch 2 Specifies a variable-pitch font.
FixedPitch 1 Specifies a fixed-pitch font.
DefaultPitch 0 Specifies default pitch.

So for "pitch" there's 3 possible values:

0, 1 and 2

and for Family there's 6:

0, 16, 32, 48, 64 and 80

I'm not very good at getting bits from bytes using bitwise operations in powerbuilder, but I think I've managed to determine the 'pitch' by "AND"-ing the rightmost bit and summing the result of the one "AND"-ed on it's left (the second lower bit). 

If not mistaken, the 'family' is simply the value of "pitchAndFamily - pitch".

I'm adapting Eric Alding's sample to use a datawindow instead of a static text control and add this information that was missing for my datawindow objects.

Later when I've finished, I'll attach that modified pbl.

For now, this is an initial piece of the code that I had to add:

// 29/01/2020: mjl, added missing attribute information 
char lch_pitchanfamily, lch_strikeout
uint lui_sout, lui_pitchandfamily, lui_pitch, lui_family
lch_strikeout = istr_logfont.lfstrikeout
lui_sout = Asc(lch_strikeout) // 0 or 1=yes strikeout is set

lch_pitchanfamily = istr_logfont.lfpitchandfamily
lui_pitchandfamily = asc(lch_pitchanfamily)


integer li_pitch, li_family
n_cst_numerical lnum

// the pitch is stored in the lower 2 bits:
li_pitch = lnum.of_bitwiseAND(lui_pitchandfamily, 1)
li_pitch += lnum.of_bitwiseAND(lui_pitchandfamily, 2)

// then this is the family
li_family = lui_pitchandfamily - li_pitch

string ls_pitch = "DefaultPitch"
choose case li_pitch
	case 0
		ls_pitch = "DefaultPitch"
	case 1
		ls_pitch = "FixedPitch"
	case 2
		ls_pitch = "VariablePitch"
		
end choose

string ls_Family = "DoNotCare"
choose case li_family
	case 0
		ls_family = "DoNotCare"
	case 8
		ls_family = "MonoFont"
	case 16
		ls_family = "Roman"
	case 32
		ls_family = "Swiss"
	case 48
		ls_family = "Modern"
	case 64 
		ls_family = "Script"
	case 80
		ls_family = "Decorative"
end choose

messagebox('charSet', asc(istr_logfont.lfcharset) )
messagebox('height',-istr_ChooseFont.iPointSize/10) // istr_logfont.lfheight )
messagebox('weight', istr_logfont.lfweight )
messagebox('pitchAndFamily', lui_pitchandfamily)
messagebox('pitch', string(li_pitch) + " " + ls_pitch)
messagebox('family', string(li_family) + " " + ls_family)

st_1.textcolor	= istr_ChooseFont.rgbColors


// this is an example of how it should look in dw source code:
//font.face="Tahoma" font.height="-10" font.weight="700"  font.family="2" font.pitch="2" font.charset="0" font.italic="1" font.underline="1" font.strikethrough="1" 

// FAMILY:
// ------
//FamilyDecorative	80	Specifies a novelty font; for example, Old English.
//FamilyScript	64	Specifies a font that is designed to look like handwriting; for example, Script and Cursive.
//FamilyModern	48	Specifies a monospace font with or without serifs. Monospace fonts are usually modern; examples include Pica, Elite, and Courier New.
//FamilySwiss	32	Specifies a proportional font without serifs; for example, Arial.
//FamilyRoman	16	Specifies a proportional font with serifs; for example, Times New Roman.
//FamilyDoNotCare	0	Specifies a generic family name, which is used when information about a font does not exist or does not matter. The default font is used.

//MonoFont	8	Specifies a monospace font.

// PITCH:
// -----
//VariablePitch	2	Specifies a variable-pitch font.
//FixedPitch	1	Specifies a fixed-pitch font.
//DefaultPitch	0	Specifies default pitch.

So give me some time to convert to the use of a dw text and I'll post it here.

Cheers

 

 

Comment
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Tuesday, 28 January 2020 15:57 PM UTC
  2. PowerBuilder
  3. # 3
Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.