Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to convert XmFontList to XmRenderTable?

50 views
Skip to first unread message

Sven

unread,
Jun 19, 2008, 6:30:32 AM6/19/08
to
Hi alltogether,

I want to convert the obsolete XmFontList (Motif 1.2) to an
XmRenderTable (Motif 2.0).

The reason for this is, that we need to define tab positions now,
which can only be done with RenderTables.

But I cannot find an instruction how to convert a given XmFontList to
an XmRenderTable. Can someone provide this information for me?

Thanks, Sven

arahne

unread,
Jun 19, 2008, 12:35:47 PM6/19/08
to

I was able to do this based on the following information:
http://www.motifdeveloper.com/tips/tip2.html

Let me know if this helps you or you need a piece
of my code.

Best regards,

Dušan Peterc
http://www.arahne.si

Sven

unread,
Jun 20, 2008, 5:25:37 AM6/20/08
to
> I was able to do this based on the following information:http://www.motifdeveloper.com/tips/tip2.html
>
"For backwards compatibility, the XmFontList has been internally re-
implemented as a Render Table (although the render table it creates
only contains font data)."

Does this mean, that I do not have to convert XmFontList to
XmRenderTable, because it already is one? If this is right, then I do
not understand why my program crashes then:

void StringDraw( HDC hDC, XmFontList fontlist, XmString string,
int x, int y, int width, unsigned alignment,
unsigned dir, XRectangle *clip )
{
Widget w = hDC->w;
GC gc = hDC->gc;
Display *display = XtDisplay( w );
Drawable d = hDC->drw;
Dimension wh, h;
XRectangle rc;

#ifndef __osf__
motif_cpp::DefaultTabRenderTable rendertable( w, fontlist );
const XmFontList& fonts = rendertable.get();
#else
XmFontList& fonts = fontlist;
#endif
if (IsZoomed( hDC, False ))
{
XmStringExtent( fontlist, string, &wh, &h );
rc.x = x;
rc.y = y;
rc.width = wh;
rc.height = h;
LRtoDR( hDC, &rc );
if (rc.height >= nTextLimit)
XmStringDraw( display, d, fonts, string, gc, rc.x, rc.y, rc.width,
alignment, dir, clip );
else if (bShowSmallText)
{
XSetForeground( display, gc, colors[CLR_GREY] );
FillRectangle( hDC, x, y, wh, h );
}
}
else
{
LCtoDC( hDC, &x, &y );
XmStringDraw( display, d, fonts, string, gc, x, y, width,
alignment, dir, clip );
}
}

Thanks, Sven

Sven

unread,
Jun 20, 2008, 5:29:02 AM6/20/08
to
Here is the essence of the code of the class:

template <size_t MAX_TABS> class TabRenderTable {
public: // --- public methods ---
TabRenderTable( Widget pParent_, XmRenderTable copy_ = 0 )
: m_pParent( pParent_ ), m_rendertable( copy_ ) {
this->add_tab_rendition( 1000.0 );
} // *** TabRenderTable() ***
~TabRenderTable() {
if ( this->m_rendertable ) {
XmRenderTableFree( this->m_rendertable );
}
}
XmRenderTable get() const {
return this->m_rendertable;
}
void add_tab_rendition( float fontunits_ = 1000.0 ) {
// 1.create an XmTab object
XmTab tabs[MAX_TABS];
for ( size_t i=0; i < MAX_TABS; i++ ) {
tabs[i] = XmTabCreate ( (float) fontunits_,
Xm100TH_FONT_UNITS,
( (i==0) ? XmABSOLUTE : XmRELATIVE ),
XmALIGNMENT_BEGINNING, "." );
}

// 2.create TabList. TabLists can be changed, copied etc. in many
ways, see manual.
// Alternativ mit XmStringTableProposeTablist()
XmTabList tablist = XmTabListInsertTabs ( NULL, tabs,
XtNumber(tabs), 0 );

// 3.create a rendition that uses the tab list
Arg args[20];
size_t argc=0;
XtSetArg ( args[argc], XmNtabList, tablist ); ++argc;
XmRendition rendition = XmRenditionCreate ( m_pParent,
XmFONTLIST_DEFAULT_TAG, args, argc );
for ( size_t i=0; i < MAX_TABS; ++i ) {
XmTabFree( tabs[i] );
}
XmTabListFree( tablist );
// 4.create a render table which uses the rendition objects
this->m_rendertable = XmRenderTableAddRenditions ( this-
>m_rendertable, &rendition, 1, XmMERGE_NEW );
XmRenditionFree( rendition );
}
void add_font_rendition( const char* pFontname_ ) {
Arg args[20];
size_t argc=0;
XtSetArg ( args[argc], XmNfontName, pFontname_ ); ++argc;
XtSetArg ( args[argc], XmNfontType, XmFONT_IS_FONT ); ++argc;
XmRendition rendition = XmRenditionCreate ( m_pParent,
XmFONTLIST_DEFAULT_TAG, args, argc );
this->m_rendertable = XmRenderTableAddRenditions ( this-
>m_rendertable, &rendition, 1, XmMERGE_NEW );
XmRenditionFree( rendition );
}
private: // --- private attributes ---
Widget m_pParent; //!< widget above in hierarchy
XmRenderTable m_rendertable; //!< Motif representation
}; // ### class TabRenderTable ###

typedef TabRenderTable<10> DefaultTabRenderTable;

0 new messages