Could I add a caption over an existing image using Go? - go

If I have font files (for different fonts), is it possible to create a caption over image using Go?

You can use my gofont library for that. See the documentation for the minimal interface.
You basically call gofont.LoadFromFile("font.ttf") and on the returned Font object, you can set the PixelHeight and R/G/B values to control the draw output.
Call font.Write() on the object to render text into your draw.Image. It is even possible to center text, using the returned x and y values returned by the function.
The library is pure Go and should work on all platforms.

Related

Can I set an image, pixel by pixel, in Apps Script?

Preferably, I'd like to use an array, iterating over each pixel and setting the R G B values.
And I don't think that I can use HTML canvas in any way. I'm hoping to build it right on top of a Google Doc without additional libraries or references to external websites.
Everything I have found on the Image Class, type is about positioning or resizing, but not helpful for stating the image.
ImageItem .setImage() looks promising, but is not particularly descriptive.
You can implement your own encoding algorithm (or migrate someone else's) and transform your pixels array into an image blob compatible with the ImageItem.setImage() method.

use ghost script to extract single spot color

I am trying to use ghostscript to extract the image for a single spot color (from a PDF), REGARDLESS of whether it would be visible when printed.
I tried using the tiffsep device, but the problem is that any of the spot color that is hidden by objects above does not get sent out.
Is there any device, or settings that would allow simply any objects regardless of visibility to be extracted to a bitmap file.
If an object overlies another in PostScript then it is absolutely correct that it causes the underlying object not to render in that position (modulo overprint) because PostScript has an opaque imaging model.
So no, you can't prevent this, its supposed to work like that.

How to read image and get your pixels in lua language

I am developing an application that generates images from certain input data through the command "iup.image" and "iup.SaveImage". Now, I need to read this image file again and retrieve the pixels.
I found the command "iup.LoadImage" but I could not find a way to proceed. Can someone help me? I am using LUA language by ZeroBrane Studio.
The pixels of an IUP image can be accessed through the WID attribute in C. IUP images are designed to be simple resources used in buttons, labels and other interface elements.
If you want to manipulate pixels in Lua you should use IM directly. You are already using IM underneath when you call iup.SaveImage and iup.LoadImage.

How does GDI function GetFontData know which font?

I have some old code that I want to port to metro. The old code uses the GDI function GetFontData to get font data from a table whose tag is being passed to it. I plan to replace it with IDWriteFontFace::TryGetFontTable.To do so I have to create a IDWriteFontFace object which requires path to the font file corresponding to the font it represents. But what I don't understand is where does GetFontData figure out the font files from whose tables it is supposed to fetch the data from? Does it do so from the device context that is passed to it?
The font is the one currently selected in the Device Context. You can retrieve it by using GetCurrentObject with object type OBJ_FONT. You can then safely cast the returned HGDIOBJ to a HFONT.
As for retrieving the font file name, that's not easy. See that SO Question
There always some font selected in Device Context (I say always because there is default font). So GetFontData returns that font depending on HDC hdc parameter.
As manuell mentioned GetFontData is similar to (HFONT)(GetCurrentObject(hdc, OBJ_FONT))

What is the correct way to autosize a Static control?

I want to adjust a Static control's size to its content size, so I need to calculate the size of its text content first. I found a way to use GetTextExtentPoint32 to calculate the size, but I need to set the DC's font to the same as the control's font first. Is there a better way to do this? I've set the Static control's font once, I think maybe I don't need to set the DC's font the second time.
What is the best way to calculate the size of a Static control's text content? And is there a better way to autosize the Static control?
It sounds to me like you've already figured out the correct way to do it. Call GetTextExtentPoint32 to figure out the ideal size of the control given the text that it contains, and then resizing the control to the calculated size.
It's a lot of work, but that's what happens when you're working with the raw Win32 API. You don't have a handy wrapper library that abstracts all this for you in a Control.AutoSize() function. You could easily write your own function and re-use it, but the Win32 standard controls do not expose an "auto-size" API.
As far as the font, you will definitely need to make sure that the device context is using the same font as the control, otherwise you'll calculate the wrong size. But you don't have to create a new device context, request a handle the static control's font, and select that into your new DC. Instead, you can just use the static control's DC using the GetDC function and passing in the handle to your static control window. Make sure that if you call GetDC, you always follow up with a call to ReleaseDC when you're finished!
However, do note some caveats of the GetTextExtentPoint32 function that may interfere with the accuracy of the size you calculate:
It ignores clipping.
It does not take into account new lines (\n) or carriage returns (\r\n) when computing the height.
It does not take into account prefix characters (those preceded in the string with ampersand) and used to denote keyboard mnemonics if your static control does not have the SS_NOPREFIX style.
It may not return an accurate result in light of the kerning that may be implemented automatically by some devices.
(This is all mentioned in the linked documentation, but does anyone actually read that?)
Perhaps an easier alternative is to draw the text the same way that the static control is already doing. Unless you have the SS_SIMPLE style set (which uses TextOut or ExtTextOut to draw text as an optimization), static controls draw their text by calling the DrawText function with the appropriate parameters, given the other control styles that are set (reference).
You can do exactly the same thing, and add the DT_CALCRECT flag in your call to the DrawText function, which causes it to determine the width and height of the rectangle required to draw the specified text without actually drawing the text.
Most windows using static text controls are dialogs, where the static control's size is expressed in dialog units (DLU), which account roughly for the size of the font. In this way, dialog controls tend to have sensible sizes.
If you are not using dialogs, you can attempt to fake dialog behavior using MapDialogRect.
Otherwise yes you must use GetTextExtentPoint32.
There is no autosize for static control as far as I know. You are doing it correct.
Use GetWinDowText to get the text of static window
Use GetDC to get the dc for the window
Use WM_GETFONT to get the font for the window and select the font into the dc
Use one of the text size calculation function to calculate the text size
Restore the the original dc font
Release dc
You will always have to select the proper font into the dc to get accurate result. Also I personally prefer DrawText with DT_CALCRECT to calculate the size of a text. Refer http://msdn.microsoft.com/en-us/library/windows/desktop/dd162498%28v=vs.85%29.aspx
With DrawText, you dont have to supply the character count if the text is NULL terminated. Plus you can combine various formatting option to adjust the calculation. For example, an Ampersand(&) character in a static control text underlines the next character. With Drawtext you will be able to calculate the size properly but in GetTextExtentPoint32 there is no provision to specify this.

Resources