Rank: Newbie Groups: Member
Joined: 2/20/2008 Posts: 4 Points: 12 Location: Swiss
|
I've the problem that I have a lot of text. Now I want to calculate how many pages I need. For that I need a cdc or HDC object of the library how can I get that object?
|
 Rank: Administration Groups: Administration
, Member
Joined: 7/17/2007 Posts: 8 Points: 27 Location: Saint-Petersburg
|
To get metrics of fonts you can use next piece of code: Quote: HDC dc=CreateDC(_T("DISPLAY"),0,0,0);
BESTVIEW::COREPREVIEW_PAGESIZE CorePreviewPageSize; ZeroMemory(&CorePreviewPageSize,sizeof(CorePreviewPageSize)); // let it be A4 sheet, i.e. 210 x 297 mm CorePreviewPageSize.dwSize=sizeof(CorePreviewPageSize); CorePreviewPageSize.dwPageWidth=21000; CorePreviewPageSize.dwPageHeight=29700; // with 10 mm margins CorePreviewPageSize.dwLeftOffset=1000; CorePreviewPageSize.dwTopOffset=1000; CorePreviewPageSize.dwWidth=CorePreviewPageSize.dwPageWidth-2*CorePreviewPageSize.dwTopOffset; CorePreviewPageSize.dwHeight=CorePreviewPageSize.dwPageHeight-2*CorePreviewPageSize.dwLeftOffset;
BESTVIEW::COREPREVIEW_COORDINATESPACE CoordinateSpace; ZeroMemory(&CoordinateSpace,sizeof(CoordinateSpace)); CoordinateSpace.dc=dc; CoordinateSpace.ViewportOrgXOffset=0; CoordinateSpace.ViewportOrgYOffset=0; // should be a positive value, let it be CorePreviewPageSize.dwPageWidth CoordinateSpace.ViewportExtWidth=CorePreviewPageSize.dwPageWidth; // should be a positive value, let it be CorePreviewPageSize.dwPageHeight CoordinateSpace.ViewportExtHeight=CorePreviewPageSize.dwPageHeight;
// here we configure HDC BESTVIEW::bvSetHdcCoordinateSpace(&CoordinateSpace,&CorePreviewPageSize);
LOGFONT LogFont; ZeroMemory(&LogFont,sizeof(LogFont)); LogFont.lfHeight=BESTVIEW::bvCalculateFontSize(24); LogFont.lfOutPrecision=OUT_TT_PRECIS; LogFont.lfQuality =PROOF_QUALITY; LogFont.lfWeight = FW_NORMAL; LogFont.lfOutPrecision=OUT_DEFAULT_PRECIS; LogFont.lfCharSet=DEFAULT_CHARSET; _tcscpy(LogFont.lfFaceName,_T("Arial"));
HFONT hFont=CreateFontIndirect(&LogFont); HFONT hOldFont=(HFONT) SelectObject(dc,hFont);
TEXTMETRIC TextMetric; ZeroMemory(&TextMetric,sizeof(TextMetric)); BOOL b=GetTextMetrics(dc,&TextMetric);
SelectObject(dc,hOldFont); DeleteObject(hFont);
DeleteDC(dc);
In this example I retrieve data for the TEXTMETRIC struct.
|