using getGlyphOutline in VB6 ? 
Author Message
 using getGlyphOutline in VB6 ?

<Win2K sp1, VB6 sp4 ... actual code used at end of this message >

I am calling getGlyphOutline passing it the hdc of the current form window
(and a single character string converted to a character code) after setting
the font of that window to the a user-chosen font/point size/style, etc.

Calling using the GGO_METRICS argument is supposed to make it ignore the
cbBuffer and lpBuffer parameters, but I can never get the call to produce
anything but a GDI error.

I am wondering if I need to set up lpBuffer which is declared as type 'any
in some special way.

thanks ! Bill

Public Const GDI_ERROR = &HFFFF
'
Public Const GGO_METRICS = 0
'
Public Type POINTAPI
        x As Long
        y As Long
End Type

Public Type FIXED
        fract As Integer
        Value As Integer
End Type

Public Type MAT2
        eM11 As FIXED
        eM12 As FIXED
        eM21 As FIXED
        eM22 As FIXED
End Type

Public Type GLYPHMETRICS
        gmBlackBoxX As Long
        gmBlackBoxY As Long
        gmptGlyphOrigin As POINTAPI
        gmCellIncX As Integer
        gmCellIncY As Integer
End Type
'
Public Declare Function GetGlyphOutline _
    Lib "gdi32" _
    Alias "GetGlyphOutlineA" _
    ( _
        ByVal hdc As Long, _
        ByVal uChar As Long, _
        ByVal fuFormat As Long, _
        lpgm As GLYPHMETRICS, _
        ByVal cbBuffer As Long, _
        lpBuffer As Any, _
        lpmat2 As MAT2 _
    ) _
    As Long
'
'
Public Sub getCharOutData(theHDC As Long, theChar As String)
    '
    Dim charCode As Long
    Dim theGlyphMetrics As GLYPHMETRICS
    Dim theMat2 As MAT2
    Dim theResult As Long
    '
    charCode = CLng(Asc(theChar))
    '
    theResult = GetGlyphOutline(theHDC, charCode, GGO_METRICS,
theGlyphMetrics, 0&, Null, theMat2)
    '
    If theResult = GDI_ERROR Then
        MsgBox "failure in getCharOutData"
    Else
        With theGlyphMetrics.gmptGlyphOrigin
            MsgBox "width = " & .x & " height = " & .y
        End With
    End If
    '
End Sub



Fri, 31 Jan 2003 03:00:00 GMT  
 using getGlyphOutline in VB6 ?
Don't EVER pass Null to an API.... if they say Null in C/C++ docs, try ByVal
0& instead.

--
MichKa

random junk of dubious value at the multilingual
http://www.trigeminal.com/ and a new book on
i18N in VB at http://www.trigeminal.com/michka.asp


Quote:
> <Win2K sp1, VB6 sp4 ... actual code used at end of this message >

> I am calling getGlyphOutline passing it the hdc of the current form window
> (and a single character string converted to a character code) after
setting
> the font of that window to the a user-chosen font/point size/style, etc.

> Calling using the GGO_METRICS argument is supposed to make it ignore the
> cbBuffer and lpBuffer parameters, but I can never get the call to produce
> anything but a GDI error.

> I am wondering if I need to set up lpBuffer which is declared as type 'any
> in some special way.

> thanks ! Bill

> Public Const GDI_ERROR = &HFFFF
> '
> Public Const GGO_METRICS = 0
> '
> Public Type POINTAPI
>         x As Long
>         y As Long
> End Type

> Public Type FIXED
>         fract As Integer
>         Value As Integer
> End Type

> Public Type MAT2
>         eM11 As FIXED
>         eM12 As FIXED
>         eM21 As FIXED
>         eM22 As FIXED
> End Type

> Public Type GLYPHMETRICS
>         gmBlackBoxX As Long
>         gmBlackBoxY As Long
>         gmptGlyphOrigin As POINTAPI
>         gmCellIncX As Integer
>         gmCellIncY As Integer
> End Type
> '
> Public Declare Function GetGlyphOutline _
>     Lib "gdi32" _
>     Alias "GetGlyphOutlineA" _
>     ( _
>         ByVal hdc As Long, _
>         ByVal uChar As Long, _
>         ByVal fuFormat As Long, _
>         lpgm As GLYPHMETRICS, _
>         ByVal cbBuffer As Long, _
>         lpBuffer As Any, _
>         lpmat2 As MAT2 _
>     ) _
>     As Long
> '
> '
> Public Sub getCharOutData(theHDC As Long, theChar As String)
>     '
>     Dim charCode As Long
>     Dim theGlyphMetrics As GLYPHMETRICS
>     Dim theMat2 As MAT2
>     Dim theResult As Long
>     '
>     charCode = CLng(Asc(theChar))
>     '
>     theResult = GetGlyphOutline(theHDC, charCode, GGO_METRICS,
> theGlyphMetrics, 0&, Null, theMat2)
>     '
>     If theResult = GDI_ERROR Then
>         MsgBox "failure in getCharOutData"
>     Else
>         With theGlyphMetrics.gmptGlyphOrigin
>             MsgBox "width = " & .x & " height = " & .y
>         End With
>     End If
>     '
> End Sub



Fri, 31 Jan 2003 03:00:00 GMT  
 using getGlyphOutline in VB6 ?
Michka wrote : "Don't EVER pass Null to an API.... if they say Null in C/C++
docs, try ByVal

Quote:
> 0& instead."

Thanks, Michka,

But in this case I don't think that's the problem. The 'lpBuffer parameter
(C type 'lpVoid) is an output parameter which, according to the GDI SDK
docs, is ignored when you make the call using the GGO_METRICS flag :

"The function only retrieves the GLYPHMETRICS structure specified by lpgm.
The other buffers are ignored. This value affects the meaning of the
function's return value upon failure; see the Return Values section."

Perhaps I haven't "selected" the font into the device context properly ?
Maybe I need to use the 'selectObject API call ?  Maybe the idea that just
assigning the font of interest to be the font of the form whose hdc I pass
in ain't it ... but I saw this somewhere in one of Appleman's font examples.

best, Bill



Quote:
> Don't EVER pass Null to an API.... if they say Null in C/C++ docs, try
ByVal
> 0& instead.

> --
> MichKa

> random junk of dubious value at the multilingual
> http://www.trigeminal.com/ and a new book on
> i18N in VB at http://www.trigeminal.com/michka.asp



> > <Win2K sp1, VB6 sp4 ... actual code used at end of this message >

> > I am calling getGlyphOutline passing it the hdc of the current form
window
> > (and a single character string converted to a character code) after
> setting
> > the font of that window to the a user-chosen font/point size/style, etc.

> > Calling using the GGO_METRICS argument is supposed to make it ignore the
> > cbBuffer and lpBuffer parameters, but I can never get the call to
produce
> > anything but a GDI error.

> > I am wondering if I need to set up lpBuffer which is declared as type
'any
> > in some special way.

> > thanks ! Bill

> > Public Const GDI_ERROR = &HFFFF
> > '
> > Public Const GGO_METRICS = 0
> > '
> > Public Type POINTAPI
> >         x As Long
> >         y As Long
> > End Type

> > Public Type FIXED
> >         fract As Integer
> >         Value As Integer
> > End Type

> > Public Type MAT2
> >         eM11 As FIXED
> >         eM12 As FIXED
> >         eM21 As FIXED
> >         eM22 As FIXED
> > End Type

> > Public Type GLYPHMETRICS
> >         gmBlackBoxX As Long
> >         gmBlackBoxY As Long
> >         gmptGlyphOrigin As POINTAPI
> >         gmCellIncX As Integer
> >         gmCellIncY As Integer
> > End Type
> > '
> > Public Declare Function GetGlyphOutline _
> >     Lib "gdi32" _
> >     Alias "GetGlyphOutlineA" _
> >     ( _
> >         ByVal hdc As Long, _
> >         ByVal uChar As Long, _
> >         ByVal fuFormat As Long, _
> >         lpgm As GLYPHMETRICS, _
> >         ByVal cbBuffer As Long, _
> >         lpBuffer As Any, _
> >         lpmat2 As MAT2 _
> >     ) _
> >     As Long
> > '
> > '
> > Public Sub getCharOutData(theHDC As Long, theChar As String)
> >     '
> >     Dim charCode As Long
> >     Dim theGlyphMetrics As GLYPHMETRICS
> >     Dim theMat2 As MAT2
> >     Dim theResult As Long
> >     '
> >     charCode = CLng(Asc(theChar))
> >     '
> >     theResult = GetGlyphOutline(theHDC, charCode, GGO_METRICS,
> > theGlyphMetrics, 0&, Null, theMat2)
> >     '
> >     If theResult = GDI_ERROR Then
> >         MsgBox "failure in getCharOutData"
> >     Else
> >         With theGlyphMetrics.gmptGlyphOrigin
> >             MsgBox "width = " & .x & " height = " & .y
> >         End With
> >     End If
> >     '
> > End Sub



Sat, 01 Feb 2003 03:00:00 GMT  
 using getGlyphOutline in VB6 ?
What operating system are you running on? I am not getting a GDI_ERROR for
the return. FWIW, I am getting back 20.

--
MichKa

random junk of dubious value at the multilingual
http://www.trigeminal.com/ and a new book on
i18N in VB at http://www.trigeminal.com/michka.asp


Quote:
> Michka wrote : "Don't EVER pass Null to an API.... if they say Null in
C/C++
> docs, try ByVal
> > 0& instead."

> Thanks, Michka,

> But in this case I don't think that's the problem. The 'lpBuffer parameter
> (C type 'lpVoid) is an output parameter which, according to the GDI SDK
> docs, is ignored when you make the call using the GGO_METRICS flag :

> "The function only retrieves the GLYPHMETRICS structure specified by lpgm.
> The other buffers are ignored. This value affects the meaning of the
> function's return value upon failure; see the Return Values section."

> Perhaps I haven't "selected" the font into the device context properly ?
> Maybe I need to use the 'selectObject API call ?  Maybe the idea that just
> assigning the font of interest to be the font of the form whose hdc I pass
> in ain't it ... but I saw this somewhere in one of Appleman's font
examples.

> best, Bill


wrote

> > Don't EVER pass Null to an API.... if they say Null in C/C++ docs, try
> ByVal
> > 0& instead.

> > --
> > MichKa

> > random junk of dubious value at the multilingual
> > http://www.trigeminal.com/ and a new book on
> > i18N in VB at http://www.trigeminal.com/michka.asp



> > > <Win2K sp1, VB6 sp4 ... actual code used at end of this message >

> > > I am calling getGlyphOutline passing it the hdc of the current form
> window
> > > (and a single character string converted to a character code) after
> > setting
> > > the font of that window to the a user-chosen font/point size/style,
etc.

> > > Calling using the GGO_METRICS argument is supposed to make it ignore
the
> > > cbBuffer and lpBuffer parameters, but I can never get the call to
> produce
> > > anything but a GDI error.

> > > I am wondering if I need to set up lpBuffer which is declared as type
> 'any
> > > in some special way.

> > > thanks ! Bill

> > > Public Const GDI_ERROR = &HFFFF
> > > '
> > > Public Const GGO_METRICS = 0
> > > '
> > > Public Type POINTAPI
> > >         x As Long
> > >         y As Long
> > > End Type

> > > Public Type FIXED
> > >         fract As Integer
> > >         Value As Integer
> > > End Type

> > > Public Type MAT2
> > >         eM11 As FIXED
> > >         eM12 As FIXED
> > >         eM21 As FIXED
> > >         eM22 As FIXED
> > > End Type

> > > Public Type GLYPHMETRICS
> > >         gmBlackBoxX As Long
> > >         gmBlackBoxY As Long
> > >         gmptGlyphOrigin As POINTAPI
> > >         gmCellIncX As Integer
> > >         gmCellIncY As Integer
> > > End Type
> > > '
> > > Public Declare Function GetGlyphOutline _
> > >     Lib "gdi32" _
> > >     Alias "GetGlyphOutlineA" _
> > >     ( _
> > >         ByVal hdc As Long, _
> > >         ByVal uChar As Long, _
> > >         ByVal fuFormat As Long, _
> > >         lpgm As GLYPHMETRICS, _
> > >         ByVal cbBuffer As Long, _
> > >         lpBuffer As Any, _
> > >         lpmat2 As MAT2 _
> > >     ) _
> > >     As Long
> > > '
> > > '
> > > Public Sub getCharOutData(theHDC As Long, theChar As String)
> > >     '
> > >     Dim charCode As Long
> > >     Dim theGlyphMetrics As GLYPHMETRICS
> > >     Dim theMat2 As MAT2
> > >     Dim theResult As Long
> > >     '
> > >     charCode = CLng(Asc(theChar))
> > >     '
> > >     theResult = GetGlyphOutline(theHDC, charCode, GGO_METRICS,
> > > theGlyphMetrics, 0&, Null, theMat2)
> > >     '
> > >     If theResult = GDI_ERROR Then
> > >         MsgBox "failure in getCharOutData"
> > >     Else
> > >         With theGlyphMetrics.gmptGlyphOrigin
> > >             MsgBox "width = " & .x & " height = " & .y
> > >         End With
> > >     End If
> > >     '
> > > End Sub



Sat, 01 Feb 2003 03:00:00 GMT  
 using getGlyphOutline in VB6 ?

Win2K with SP1 installed. Glad it does something for you :)  best, Bill

"Michael (michka) Kaplan" wrote : "What operating system are you running on?
I am not getting a GDI_ERROR for the return. FWIW, I am getting back 20."



Sat, 01 Feb 2003 03:00:00 GMT  
 using getGlyphOutline in VB6 ?

I am on NT4 SP6a. What is Err.LastDllError after the call? Something like
ERROR_INVALID_FLAGS or ERROR_CAN_NOT_COMPLETE? (1002 or 1003).

--
MichKa

random junk of dubious value at the multilingual
http://www.trigeminal.com/ and a new book on
i18N in VB at http://www.trigeminal.com/michka.asp


Quote:
> Win2K with SP1 installed. Glad it does something for you :)  best, Bill

> "Michael (michka) Kaplan" wrote : "What operating system are you running
on?
> I am not getting a GDI_ERROR for the return. FWIW, I am getting back 20."



Sat, 01 Feb 2003 03:00:00 GMT  
 using getGlyphOutline in VB6 ?

"Michael (michka) Kaplan wrote : "What is Err.LastDllError after the call?
Something like

Quote:
> ERROR_INVALID_FLAGS or ERROR_CAN_NOT_COMPLETE? (1002 or 1003)."

1003 every time it's called.

best, Bill



Sat, 01 Feb 2003 03:00:00 GMT  
 using getGlyphOutline in VB6 ?

Ah, just got a Win2K SP1 machine to check this with, I can repro it here,
too. I will see if I can figure out what is going on.

--
MichKa

random junk of dubious value at the multilingual
http://www.trigeminal.com/ and a new book on
i18N in VB at http://www.trigeminal.com/michka.asp


Quote:

> "Michael (michka) Kaplan wrote : "What is Err.LastDllError after the call?
> Something like
> > ERROR_INVALID_FLAGS or ERROR_CAN_NOT_COMPLETE? (1002 or 1003)."

> 1003 every time it's called.

> best, Bill



Sat, 01 Feb 2003 03:00:00 GMT  
 using getGlyphOutline in VB6 ?

Two things wrong with your sample code (on Win2K here, no service pack).

First, make sure you have a true type font on your hDC (form1.Font in my
test).
Second, make sure you initialize the Matrix (mat2) to something, such as:
    'Assuming VB fills in 0's for all other values, the
    'following gives an identity matrix
    theMat2.eM11.Value = 1
    theMat2.eM22.Value = 1

-Dan



Quote:
> Ah, just got a Win2K SP1 machine to check this with, I can repro it here,
> too. I will see if I can figure out what is going on.

> --
> MichKa

> random junk of dubious value at the multilingual
> http://www.trigeminal.com/ and a new book on
> i18N in VB at http://www.trigeminal.com/michka.asp



> > "Michael (michka) Kaplan wrote : "What is Err.LastDllError after the
call?
> > Something like
> > > ERROR_INVALID_FLAGS or ERROR_CAN_NOT_COMPLETE? (1002 or 1003)."

> > 1003 every time it's called.

> > best, Bill



Sat, 01 Feb 2003 03:00:00 GMT  
 using getGlyphOutline in VB6 ?
Ok, just found out the problem.... if you do not set the MAT2 structure up,
then you will not have good return values, even when the function DOES
succeed. So the answer is to set up that structure first.

--
MichKa

random junk of dubious value at the multilingual
http://www.trigeminal.com/ and a new book on
i18N in VB at http://www.trigeminal.com/michka.asp



Quote:
> Ah, just got a Win2K SP1 machine to check this with, I can repro it here,
> too. I will see if I can figure out what is going on.

> --
> MichKa

> random junk of dubious value at the multilingual
> http://www.trigeminal.com/ and a new book on
> i18N in VB at http://www.trigeminal.com/michka.asp



> > "Michael (michka) Kaplan wrote : "What is Err.LastDllError after the
call?
> > Something like
> > > ERROR_INVALID_FLAGS or ERROR_CAN_NOT_COMPLETE? (1002 or 1003)."

> > 1003 every time it's called.

> > best, Bill



Sat, 01 Feb 2003 03:00:00 GMT  
 using getGlyphOutline in VB6 ?


Fri, 19 Jun 1992 00:00:00 GMT  
 using getGlyphOutline in VB6 ?

Thanks Michael and Dan !
Following the suggestions of Dan Jones and Michael Kaplan, the code below
sets up the MAT2 type as an indentity matrix.

I also found that unless I passed in 'vbNullString for the 'lpBuffer
parameter this would not work.

Now I have to make sense of the units that are being reported in the
GlyphMetrics structure : back to Appleman :)

best, Bill

Option Explicit
'
Public Const GDI_ERROR = &HFFFF
'
Public Const GGO_METRICS = 0
Public Const GGO_BITMAP = 1
Public Const GGO_GLYPH_INDEX = &H80
Public Const GGO_GRAY2_BITMAP = 4
Public Const GGO_GRAY4_BITMAP = 5
Public Const GGO_GRAY8_BITMAP = 6
Public Const GGO_NATIVE = 2

Public Type POINTAPI
        x As Long
        y As Long
End Type

Public Type FIXED
        fract As Integer
        Value As Integer
End Type

Public Type MAT2
        eM11 As FIXED
        eM12 As FIXED
        eM21 As FIXED
        eM22 As FIXED
End Type

Public Type GLYPHMETRICS
        gmBlackBoxX As Long
        gmBlackBoxY As Long
        gmptGlyphOrigin As POINTAPI
        gmCellIncX As Integer
        gmCellIncY As Integer
End Type
'
Public Declare Function GetGlyphOutline _
    Lib "gdi32" _
    Alias "GetGlyphOutlineA" _
    ( _
        ByVal hdc As Long, _
        ByVal uChar As Integer, _
        ByVal fuFormat As Integer, _
        lpgm As GLYPHMETRICS, _
        ByVal cbBuffer As Long, _
        ByVal lpBuffer As Any, _
        lpmat2 As MAT2 _
    ) _
    As Long

Public Sub getCharOutData(theHDC As Long, theChar As String)
    '
    Dim theGlyphMetrics As GLYPHMETRICS
    Dim theMat2 As MAT2
    Dim theResult As Long
    '
    With theMat2
        .eM11.Value = 1
        .eM22.Value = 1
    End With
    '
    theResult = GetGlyphOutline(theHDC, Asc(theChar), GGO_METRICS,
theGlyphMetrics, 0, vbNullString, theMat2)
    '
    If theResult = GDI_ERROR Then
        '
        ' for debugging only
        MsgBox "failure in getCharOutData : Err last dll #" &
Err.LastDllError
        '
    Else
        '
        ' for debugging only
        With theGlyphMetrics.gmptGlyphOrigin
            MsgBox "width = " & .x & " height = " & .y
        End With
        '
    End If
    '
End Sub



Sat, 01 Feb 2003 03:00:00 GMT  
 using getGlyphOutline in VB6 ?

You can also pass ByVal 0& (both equate to null in C)

--
MichKa

random junk of dubious value at the multilingual
http://www.trigeminal.com/ and a new book on
i18N in VB at http://www.trigeminal.com/michka.asp


Quote:
> Thanks Michael and Dan !
> Following the suggestions of Dan Jones and Michael Kaplan, the code below
> sets up the MAT2 type as an indentity matrix.

> I also found that unless I passed in 'vbNullString for the 'lpBuffer
> parameter this would not work.

> Now I have to make sense of the units that are being reported in the
> GlyphMetrics structure : back to Appleman :)

> best, Bill

> Option Explicit
> '
> Public Const GDI_ERROR = &HFFFF
> '
> Public Const GGO_METRICS = 0
> Public Const GGO_BITMAP = 1
> Public Const GGO_GLYPH_INDEX = &H80
> Public Const GGO_GRAY2_BITMAP = 4
> Public Const GGO_GRAY4_BITMAP = 5
> Public Const GGO_GRAY8_BITMAP = 6
> Public Const GGO_NATIVE = 2

> Public Type POINTAPI
>         x As Long
>         y As Long
> End Type

> Public Type FIXED
>         fract As Integer
>         Value As Integer
> End Type

> Public Type MAT2
>         eM11 As FIXED
>         eM12 As FIXED
>         eM21 As FIXED
>         eM22 As FIXED
> End Type

> Public Type GLYPHMETRICS
>         gmBlackBoxX As Long
>         gmBlackBoxY As Long
>         gmptGlyphOrigin As POINTAPI
>         gmCellIncX As Integer
>         gmCellIncY As Integer
> End Type
> '
> Public Declare Function GetGlyphOutline _
>     Lib "gdi32" _
>     Alias "GetGlyphOutlineA" _
>     ( _
>         ByVal hdc As Long, _
>         ByVal uChar As Integer, _
>         ByVal fuFormat As Integer, _
>         lpgm As GLYPHMETRICS, _
>         ByVal cbBuffer As Long, _
>         ByVal lpBuffer As Any, _
>         lpmat2 As MAT2 _
>     ) _
>     As Long

> Public Sub getCharOutData(theHDC As Long, theChar As String)
>     '
>     Dim theGlyphMetrics As GLYPHMETRICS
>     Dim theMat2 As MAT2
>     Dim theResult As Long
>     '
>     With theMat2
>         .eM11.Value = 1
>         .eM22.Value = 1
>     End With
>     '
>     theResult = GetGlyphOutline(theHDC, Asc(theChar), GGO_METRICS,
> theGlyphMetrics, 0, vbNullString, theMat2)
>     '
>     If theResult = GDI_ERROR Then
>         '
>         ' for debugging only
>         MsgBox "failure in getCharOutData : Err last dll #" &
> Err.LastDllError
>         '
>     Else
>         '
>         ' for debugging only
>         With theGlyphMetrics.gmptGlyphOrigin
>             MsgBox "width = " & .x & " height = " & .y
>         End With
>         '
>     End If
>     '
> End Sub



Sat, 01 Feb 2003 03:00:00 GMT  
 
 [ 13 post ] 

 Relevant Pages 

1. need help to use getglyphoutline api to work in VB6

2. Help needed with GetGlyphOutline

3. Vertically Centering Characters w/ GetGlyphOutline

4. GetGlyphOutline not working in VB 5.0

5. GetGlyphOutline

6. How to use WinAPI:GetGlyphOutline ?

7. GetGlyphOutline and UNICODE

8. Help needed with GetGlyphOutline

9. Help needed with GetGlyphOutline

10. GetGlyphOutline and GGO_GLYPH_INDEX

11. How to use WinAPI:GetGlyphOutline ?

12. VB6 class module turns into regular module using VB6 IDE

 

 
Powered by phpBB® Forum Software