How do I know the length of the graphic string in pixels
- Eugene Lutsenko
- Posts: 1649
- Joined: Sat Feb 04, 2012 2:23 am
- Location: Russia, Southern federal district, city of Krasnodar
- Contact:
How do I know the length of the graphic string in pixels
How do I know the pixel length and height of the graphic string
Re: How do I know the length of the graphic string in pixels
DC_GraQueryTextbox(cString,cFont) will return the needed size for displaying 'cString' in font 'cFont', i.e.:
Code: Select all
? DC_GraQueryTextbox('Eugene Lutsenko','10.Arial') // {101,16}
Best regards,
Tom
"Did I offend you?"
"No."
"Okay, give me a second chance."
Tom
"Did I offend you?"
"No."
"Okay, give me a second chance."
- Eugene Lutsenko
- Posts: 1649
- Joined: Sat Feb 04, 2012 2:23 am
- Location: Russia, Southern federal district, city of Krasnodar
- Contact:
Re: How do I know the length of the graphic string in pixels
Thank you, Tom! I have the impression that I just can not always find a description of the desired function, though I understand that it exists
- Eugene Lutsenko
- Posts: 1649
- Joined: Sat Feb 04, 2012 2:23 am
- Location: Russia, Southern federal district, city of Krasnodar
- Contact:
Re: How do I know the length of the graphic string in pixels
And yet, this feature does not work with all graphic fonts, probably because of their names. It seems it has nothing to do with the fact bitmap font or a vector. In addition it is clear that many fonts do not support Russian encoding. But that's nothing, because quite a few support and in general enough of them.
[/size]
Code: Select all
#include "appevent.ch"
#include "axcdxcmx.ch"
#include "collat.ch"
#include "common.ch"
#include "dbedit.ch"
#include "dbfdbe.ch"
#include "dcapp.ch"
#include "dcbitmap.ch"
#include "dccargo.ch"
#include "dccursor.ch"
#include "dcdialog.ch"
#include "dcdir.ch"
#include "dcfiles.ch"
#include "dcgra.ch"
#include "dcgraph.ch" // графика
#include "BdColors.Ch" // графика
#include "dccolors.ch" // графика
#include "dcprint.ch" // графика
*#INCLUDE "rmchart.CH" // графика
#include "dcicon.ch"
#include "dcmsg.ch"
#include "dcpick.ch"
#include "deldbe.ch"
#include "directry.ch"
#include "dmlb.ch"
#include "express.ch"
#include "fileio.ch"
#include "font.ch"
#include "gra.ch"
#include "inkey.ch"
#include "memvar.ch"
#include "natmsg.ch"
#include "prompt.ch"
#include '_dcdbfil.ch'
*#INCLUDE "dcads.CH"
#include "set.ch"
#include "std.ch"
#include "xbp.ch"
#include '_dcappe.ch'
#include 'dcscope.ch'
#include '_dcstru.ch'
#include 'dcfields.ch'
#include 'dccolor.ch'
#include "Fileio.ch" // Max_DB
#pragma library( "ascom10.lib" )
#pragma library( "dclip1.lib" )
#pragma library( "dclip2.lib" )
#pragma library( "dclipx.lib" )
#pragma library( "xbtbase1.lib" )
#pragma library( "xbtbase2.lib" )
#pragma library( "xppui2.lib" )
*************************************
PROCEDURE AppSys
// Рабочий стол остается окном приложения
RETURN
*************************************
PROCEDURE Main()
LOCAL GetList := {}, oStatic
LOCAL oPS, oDevice, oDlg
DC_IconDefault(1000)
SET COLLATION TO SYSTEM // Руссификация
@0, 0 DCSAY "Gra Fonts" FONT ("22.HelveticalBold") SIZE 0
PUBLIC X_MaxW := 1800, Y_MaxW := 850 // Размер графического окна в пикселях
kD = 33
aFonts := XbpFont():new():list()
FOR ki=1 TO LEN(aFonts) STEP kD //
@ 2,1 DCSTATIC TYPE XBPSTATIC_TYPE_RECESSEDBOX SIZE X_MaxW, Y_MaxW PIXEL;
OBJECT oStatic
DCREAD GUI FIT ;
EVAL {||_PresSpace(oStatic,ki,kD,aFonts)}
oStatic := nil
NEXT
RETURN
*************************************************
STATIC FUNCTION _PresSpace( oStatic, ki, kD, aFonts )
LOCAL oPS, oDevice
oPS := XbpPresSpace():new() // Create a PS
oDevice := oStatic:winDevice() // Get the device context
oPS:create( oDevice ) // Link device context to PS
oPS:SetViewPort( { 0, 0, X_MaxW, Y_MaxW } )
oStatic:paint := {|mp1,mp2,obj| mp1 := LC_MultiLine( oPS, oStatic, ki, kD, aFonts ) }
RETURN NIL
*******************************************************
STATIC FUNCTION LC_MultiLine( oPS, oStatic, mi, mD, aFonts )
LOCAL i, j, cFont, nRow, lOk, GetList := {}, nHeight
LOCAL GetOptions
LOCAL oSourcePS, oBitmap, oClipBoard, aPos
****** Исследование графических шрифтов
****** Инициализация графического шрифта для надписи внизу графической экранной формы
* aFonts := XbpFont():new():list() // Все доступные шрифты
* oFont := XbpFont():new():create("48.Helvetica") // Конкретный шрифт с указанием размера
oFont := aFonts[1] // Конкретный шрифт по номеру из списка (всего доступно 1681 графических шрифтов)
GraSetFont(oPS , oFont) // установить шрифт
aAttrF := ARRAY( GRA_AS_COUNT )
aAttrF [ GRA_AS_COLOR ] := GRA_CLR_BLACK
* aAttrF [ GRA_AS_BOX ] := { 300, 50 } // Размер поля вывода (только для векторных шрифтов)
aAttrF [ GRA_AS_HORIZALIGN ] := GRA_HALIGN_CENTER // Выравнивание символов по горизонтали по центру относительно точки начала вывода
aAttrF [ GRA_AS_VERTALIGN ] := GRA_VALIGN_HALF // Выравнивание символов по вертикали по средней линии относительно точки начала вывода
GraSetAttrString( oPS, aAttrF )
GraStringAt( oPS, { 200, 10 }, "Всего шрифтов:"+ALLTRIM(STR(LEN(aFonts),15)) )
aAttrF := ARRAY( GRA_AS_COUNT )
aAttrF [ GRA_AS_COLOR ] := GRA_CLR_BLACK
aAttrF [ GRA_AS_BOX ] := { 60, 30 } // Размер поля вывода для векторных шрифтов
aAttrF [ GRA_AS_HORIZALIGN ] := GRA_HALIGN_LEFT // Выравнивание символов по горизонтали по центру относительно точки начала вывода
aAttrF [ GRA_AS_VERTALIGN ] := GRA_VALIGN_HALF // Выравнивание символов по вертикали по средней линии относительно точки начала вывода
GraSetAttrString( oPS, aAttrF ) // Установить символьные атрибуты
PRIVATE aTxtPar[2]
S = 1
LimJ = IF(mi+mD-1 <= LEN(aFonts), mi+mD-1, LEN(aFonts))
FOR j=mi TO LimJ
oFont := aFonts[j]
GraSetFont(oPS , oFont) // установить шрифт
Mess = "Шрифт №"+ALLTRIM(STR(j,15))+IF(oFont:vector,"-векторный","-растровый")
aTxtPar = DC_GraQueryTextbox( Mess, oFont )
GraStringAt( oPS, { 100, 20+(S-1)*25 }, Mess+". Width="+ALLTRIM(STR(aTxtPar[1]))+". Height="+ALLTRIM(STR(aTxtPar[2])) )
S++
NEXT
**** Записать графический файл
* cFileName = "Fonts"+STRTRAN(STR(mi,4)," ","0")+"-"+STRTRAN(STR(LimJ,4)," ","0")+".bmp"
* DC_Scrn2ImageFile( oStatic, cFileName )
* cFileName = "Fonts"+STRTRAN(STR(mi,4)," ","0")+"-"+STRTRAN(STR(LimJ,4)," ","0")+".jpg"
* DC_Scrn2ImageFile( oStatic, cFileName )
cFileName = "Fonts"+STRTRAN(STR(mi,4)," ","0")+"-"+STRTRAN(STR(LimJ,4)," ","0")+".gif"
DC_Scrn2ImageFile( oStatic, cFileName )
*** Конец исследования шрифтов ********************
RETURN NIL
FUNCTION DC_Scrn2ImageFile( oXbp, cFileName, nFormat )
LOCAL oSourcePS, oBitmap, oClipBoard, aPos
oSourcePS := oXbp:lockPS()
IF oXbp:isDerivedFrom('XbpDialog')
aPos := { -4, -4 }
ELSE
aPos := { 0, 0 }
ENDIF
oBitmap := GraSaveScreen( oSourcePS, aPos, oXbp:currentSize() )
RETURN oBitMap:saveFile( cFileName, nFormat )
Re: How do I know the length of the graphic string in pixels
Hi, Eugene.
Looks you're using the function with a font object. Since I use eXpress++ 1.9.257, I don't know whether there's a newer version of it in build 258 or later, but in my version, a font compound name should be the parameter!
Font compound names should reflect Xbase++ notation and local attributes. "10.Arial Bold" is valid in english environments only; it's "10.Arial Fett" in german(y) for example. Maybe your'e struggling with something here.
Looks you're using the function with a font object. Since I use eXpress++ 1.9.257, I don't know whether there's a newer version of it in build 258 or later, but in my version, a font compound name should be the parameter!
Font compound names should reflect Xbase++ notation and local attributes. "10.Arial Bold" is valid in english environments only; it's "10.Arial Fett" in german(y) for example. Maybe your'e struggling with something here.
Best regards,
Tom
"Did I offend you?"
"No."
"Okay, give me a second chance."
Tom
"Did I offend you?"
"No."
"Okay, give me a second chance."
- Eugene Lutsenko
- Posts: 1649
- Joined: Sat Feb 04, 2012 2:23 am
- Location: Russia, Southern federal district, city of Krasnodar
- Contact:
Re: How do I know the length of the graphic string in pixels
Yes, things do not always work, but usually that works, is enough to achieve the goal