FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Rotated Text, Save Bitmap

 
Post new topic   Reply to topic     Forum Index -> DFL
View previous topic :: View next topic  
Author Message
dsimcha



Joined: 24 Oct 2008
Posts: 16

PostPosted: Tue Jul 06, 2010 9:55 pm    Post subject: Rotated Text, Save Bitmap Reply with quote

I'm working on a plotting library using DFL for basic GUI functionality. Right now, some (very) basic functionality is working, but I'm hung up on trying to make two things work.

First, how does one get rotated text of the type that would be appropriate for the y-axis label of a graph?

Secondly, how does one get access to the underlying bits of a Bitmap to, for example, write the image out to a file?

Thanks in advance.
Back to top
View user's profile Send private message
Chris Miller



Joined: 27 Mar 2004
Posts: 514
Location: The Internet

PostPosted: Thu Jul 08, 2010 10:37 pm    Post subject: Re: Rotated Text, Save Bitmap Reply with quote

To rotate text, you could write the text normally into a temporary bitmap, and then rotate the pixels as you copy them to where you want it.

DFL doesn't directly have a way to get the pixel data of a Bitmap (yet). You could take a look at h3r3tic's DrawingArea addon. Here's a list of GDI functions* like GetDIBits you might be interested in, you can use with Bitmap.handle.

* http://msdn.microsoft.com/en-us/library/dd183385(v=VS.85).aspx (not linkable or clickable)
Back to top
View user's profile Send private message
dsimcha



Joined: 24 Oct 2008
Posts: 16

PostPosted: Sat Jul 10, 2010 10:51 pm    Post subject: Re: Rotated Text, Save Bitmap Reply with quote

Chris Miller wrote:
To rotate text, you could write the text normally into a temporary bitmap, and then rotate the pixels as you copy them to where you want it.


I thought of this, but I couldn't figure out how to implement it. Is there a DFL API to rotate the pixels of a Bitmap object, or would I have to mess w/ the Win32 API directly? It doesn't appear to be do-able from Graphics.copyTo.
Back to top
View user's profile Send private message
dsimcha



Joined: 24 Oct 2008
Posts: 16

PostPosted: Sat Jul 24, 2010 1:50 pm    Post subject: Reply with quote

Here's some code that does rotated text. It's buggy in terms of text measuring/wrapping, but it's better than nothing and serves the purposes of my plotting lib. Could you please fold it into the next release of DFL in drawing.d so I can stop requiring users of Plot2Kill (my plotting library) that use the DFL backend to patch DFL?

Code:


// This implements rotated fonts.  Thanks to Robert Jacques for the code.
class RFont : Font {
    /// ditto
    this(Dstring, float emSize, FontStyle style = FontStyle.REGULAR,
        GraphicsUnit unit = GraphicsUnit.POINT)
    {
        this(name, emSize, style, unit, DEFAULT_CHARSET, FontSmoothing.DEFAULT);
    }


    /// ditto
    this(Dstring name, float emSize, FontStyle style,
        GraphicsUnit unit, FontSmoothing smoothing)
    {
        this(name, emSize, style, unit, DEFAULT_CHARSET, smoothing);
    }

    // /// ditto
    // This is a somewhat internal function.
    // -gdiCharSet- is one of *_CHARSET from wingdi.h
    this(Dstring name, float emSize, FontStyle style,
        GraphicsUnit unit, ubyte gdiCharSet,
        FontSmoothing smoothing = FontSmoothing.DEFAULT)
    {
        LogFont lf;

        _unit = unit;

        lf.faceName = name;

        lf.lf.lfEscapement  = 900;
        lf.lf.lfOrientation = 900;

        lf.lf.lfHeight = -getLfHeight(emSize, unit);
        _style(lf, style);

        lf.lf.lfCharSet = gdiCharSet;
        lf.lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
        lf.lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
        //lf.lf.lfQuality = DEFAULT_QUALITY;
        lf.lf.lfQuality = cast(BYTE) smoothing;
        lf.lf.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;

        super(_create(lf));

        _fstyle = style;
        _initLf(lf);
    }
}
Back to top
View user's profile Send private message
Chris Miller



Joined: 27 Mar 2004
Posts: 514
Location: The Internet

PostPosted: Tue Jul 27, 2010 7:47 pm    Post subject: Reply with quote

How about this, I added an overload to the Font constructor in subversion for now that lets you customize the LogFont:
Code:
this(ref LogFont lf, float emSize, FontStyle style, GraphicsUnit unit)
so you could use this to keep RFont in your project and use the new Font constructor.
If it's good I'll include it in the next snapshot and release.
Back to top
View user's profile Send private message
dsimcha



Joined: 24 Oct 2008
Posts: 16

PostPosted: Wed Jul 28, 2010 1:34 pm    Post subject: Reply with quote

Chris Miller wrote:
How about this, I added an overload to the Font constructor in subversion for now that lets you customize the LogFont:
Code:
this(ref LogFont lf, float emSize, FontStyle style, GraphicsUnit unit)
so you could use this to keep RFont in your project and use the new Font constructor.
If it's good I'll include it in the next snapshot and release.


That sounds great.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> DFL All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group