I recently saw that when sfml loads a font from memory by receiving a const char*.
How does this represent a font?
I also saw the arial.hpp file only contains a huge array of numbers(chars), which you can feed into the LoadFont function.
the font class in SFML also holds an image, but I don't know how it gets set since there's no load/set function for it, and images are made out of unsigned chars, not char arrays like what the arial font is made of.
How does all this stuff fit together, and how do I create and load a font?
(sfml specific steps would be nice also)
As far as I can tell, there is no LoadFont function in SFML. There are Font::LoadFromFile and Font::LoadFromMemory. I'll assume you're talking about those.
From the documentaiton for Font::LoadFromMemory:
Load the font from a file in memory.
It is for cases when you have loaded something into memory. That is, if you're not using the normal filesystem. Maybe you have all of your data in .zip files, so using standard file IO won't be useful. You load it into a block of memory (the aforementioned array of bytes), and pass it to this function.
The 2.0 documentation is more complete, as it lists the font formats that are accepted.
Related
I'm using Pango for text layouting without the cairo backend (currently testing with the win32 backend). And I like to know if pango is capable of a flow layout around an image, or any given container. Or maybe inside a custom container.
Something like this: Flow around image
I have checked many examples and the Pango API and didn't found such a feature. Maybe I'm missing something or Pango does not have this feature.
As I said in this answer, you can't. I went through the source code Pango graphics handling is primitive to the point of uselessness. Unless there's been some major reworking in the past year, which the release notes don't indicate, it's probably the same now.
The image you provide as an example is only available as PDF at the moment which requires every line, word and glyph be hard-positioned on the page. While theoretically possible to check the alpha channel of the image to wrap the text around the actual image instead of the block it contains, this has not (to the best of my knowledge) ever been implemented in a dynamic output system.
Pango, specifically, cannot even open "holes" in the text for graphics to be added later and, at the code level, doesn't even have the concept of a multi-line cell - hence a line being the size of its largest component.
Your best bet is to look at WebKit for more complex displays. I, for one, have pretty much given up on Pango and it seems to be getting less popular.
I making a program that takes screenshots, I use GetFrontBufferData and D3DXSaveSurfaceToFile. But now I am facing trouble.D3DXSaveSurfaceToFile uses d3dx9_43.dll, that cannot be static linked, and program didn't work on pc without directx. How I can save surface, using only D3D?
GetFrontBufferData gets you a pointer to the IDirect3DSurface9. Calling IDirect3DSurface9::GetDesc will give you D3DSURFACE_DESC, describing the image data. Most important for saving it to a file are Format, Width and Height members. Then, you can call IDirect3DSurface9::LockRect to obtain the actual data. The output of this function is a D3DLOCKED_RECT, which contains the image data in the pBits member. Note that the image data might not be tightly packed, you will have to take into account the Pitch member of the D3DLOCKED_RECT. You can then use any static linkable image library, (eg. DevIL) to write the image out to disk, or roll-your-own image writer (writing a BMP/TGA is quite easy).
Or, you could just install the proper DirectX runtime on the target computer, which would probably be a lot easier.
The title sums this one up. If I'm loading ~200 images of various size. How can I load just the header so I can know the size of each image?
Currently I find it takes a lot of cpu/memory and IO to load them all in to memory just for the size (I'm trying to generate an atlas from them).
QImage doesn't seem to have a way to do this. QImageReader sounded like it was what I wanted, yet this still seems to just go ahead and read the whole image, so not really sure what its purpose is. Is there another class or some way to use either of the class I've mentioned to only grab the image size from header?
How can I load just the header so I can know the size of each image?
Apparently it looks like you have assumed that image file header(first few bytes of) contains the size of the image. This does not hold true(at least not for all image format type). I checked it for few of formats(PNG).
Currently I find it takes a lot of cpu/memory and IO to load them all
in to memory just for the size
As you have mentioned that you are trying to load around ~200 image at one time just to find the size. This design does not looks good and we should try to decompose our problem into the smaller one. So here the efficient approach might be to open one file and find the size store into some data structure and close the file. If there is other part of your program which needs that ~200 image should be loaded into the memory then we should try to think on how can we avoid it.
QImage doesn't seem to have a way to do this?
It does not have as there seem to be no portable/consistent way to do it for all type of image format. However if you are aware about any file format which contains the header you may write small helper function which can open the file and read the header and find the size. But this helper function would be very specific to a particular type of image format and we may need to write different logic to read the header(all image formats have different header size and information).
I've done a bit of research but haven't found anything useful so far.
In short I would like to be able to create a bitmap/canvas in memory and use an api which has functions for drawing primitive shapes and text on that bitmap and read the memory directly. This should be completely done in memory and not need a window system or something like Qt or GTK.
Why? I'm writing for the raspberry pi and am interfacing with a 256x64 4 bit greyscale OLED display over spi. This is all working fine so far. I've written a couple of functions for writing text etc, but am wondering if there is already a library I can use. I double buffer the display so I just need to manipulate the image in memory and then read the entire picture in one.
I can easily do this in windows but am not sure the best way to do this in linux
I've used Image Magick to do similar things. It supports Bitmap and SVG. http://www.imagemagick.org/script/index.php
Is there a C++ library that takes a string and a font file and returns the pixel representation of that string using that font? For example, I wrote a short PHP script that draws a single letter using Courier and then pulls out the individual pixels:
I can convert that to an array of color intensity codes and use it, but it means I need to hardcode every character I want to use, in every font, and I lose things like ligatures and intelligent kerning that only come up when multiple characters are drawn together. Is there a way in C++ to just do this directly, given the TTF file for the font I want to use? I'm using Linux, so I can't depend on Windows API functions like GetGlyphOutline
Is there a C++ library that takes a string and a font file
There's C library that can be used to do the same thing. It is called Freetype2. It is relatively easy to use. If you want to keep things portable and relatively lightweight, using Freetype2 is the way to do it. On linux system it is probably already installed.
Also, cross-platform GUI toolkit normally provide some kind of "font" class that can be used to do what you want. For example, in Qt 4 you could use QFont to draw text on Qimage and then extract individual pixels, plus operatign systems (ones that have concept of "font") normally provide some kind of font manipulation API as well.