Why emscripten emscripten_get_canvas_element_size does not return the DOM element size? - html5-canvas

In the code of a big project using emscripten 2.0.8, a function tries to retrieve the size of the DOM element for a specific canvas in ordre to initialize.
double w=0, h=0;
emscripten_get_element_css_size(canvasCssSelector, &w, &h);
But I monitored the values with a log and they don't match at all with the size I get in my browser. Even more confusing, the size never changes while I do resize my window (and the canvas). It just stays constant to 300x150 (could be an initialization by code somewhere or default values, but it is still wrong regarding the actual DOM).
Doc says
EMSCRIPTEN_RESULT emscripten_get_canvas_element_size(const char *target, int *width, int *height)
Gets the current pixel width and height of the given Canvas element in the DOM.

Related

How is the size of a surface determined in Vulkan?

I'm following the Vulkan Tutorial and the section Window Surface says that on Windows a VkSurfaceKHR object is created using the following code:
VkWin32SurfaceCreateInfoKHR createInfo = {};
createInfo.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR;
createInfo.hwnd = glfwGetWin32Window(window);
createInfo.hinstance = GetModuleHandle(nullptr);
if (vkCreateWin32SurfaceKHR(instance, &createInfo, nullptr, &surface) != VK_SUCCESS) {
throw std::runtime_error("failed to create window surface!");
}
But we never specify the extents of the surface in the createInfo object.
However calling the vkGetPhysicalDeviceSurfaceCapabilitiesKHR function returns a VkSurfaceCapabilitiesKHR object which has a currentExtent field which according to the documentation is
the current width and height of the surface, or the special value (0xFFFFFFFF, 0xFFFFFFFF) indicating that the surface size will be determined by the extent of a swapchain targeting the surface.
So in the special case that currentExtent equals (0xFFFFFFFF, 0xFFFFFFFF) we know that the size of the surface is determined by the swapchain targeting the surface, but in all other cases it seems that the surface already has a size originating from somewhere else and we are expected to match the extents of the swapchain to that size.
So where does the size of the surface come from when it's not being determined by the swapchain?
On Windows, the initial extents of the surface are equal to the width and height values you set when creating the window (minus window borders, menus, etc.).
The extents value returned by vkGetPhysicalDeviceSurfaceCapabilitiesKHR also updates automatically when the window is resized by the user (on Windows).
It is also important to note that on different platforms, max, min, and current extents behave differently. On Windows, the output surface must always be equal to the paintable window size, so they will all be equal.

Directxtk SpriteFont blurry when not whole number

The text becomes blurry if I use a non whole number for the position of the string. Any ideas what is causing this and how to correct it?
this->pSpriteBatch->Begin();
this->pSpriteFont->DrawString(this->pSpriteBatch, szTempMessage, XMFLOAT2(x, y), color);
this->pSpriteBatch->End();
I'm calling it with only the position and color parameters.
SpriteBatch renders using CommonStates::LinearClamp by default, so it will be blurry if you rendering to a sub-pixel location. You can try using another filtering mode by overriding it with Begin:
// create an instance of CommonStates as pStates
pSpriteBatch->Begin(SpriteSortMode_Deferred,
nullptr /*use default blend state */,
pStates->AnisotropicClamp());
pSpriteFont->DrawString(...);
pSpriteBatch->End();
See if that improves your results.

GWT - Getting the current size of an image

I use the GWT image class with a ClickHandler to trigger actions when specific areas of the image are clicked. In order to specify these areas, I use the image's dimensions. The problem occurs when you change the size of your browser window. While the image rescales nicely, the getWidth() and getHeight() methods still return the image's original size, not the size after rescaling.
Do you know a way to retrieve the current size of the image?
.getElement().getOffsetWidgth() ? and .getOffsetHeight().
I think thats what you need.
That will return the current size of the element in the Dom, including any decorations like borders in the CSS.

font size bug with CGContextShowTextAtPoint

I have some rather simple code drawing some text into a CGContext. Here is an excerpt (slightly edited).
CGContextSelectFont(context, "Helvetica", 1.5, kCGEncodingMacRoman);
CGContextShowTextAtPoint(context, xpos, ypos, "Hello", 5);
The text renders ok. For some unknown reason, however, the font changes to a smaller size after I click in the view containing the context. Also when I resize the window containing the view the font returns to original size. What is the reason for this?
1.5 points is mighty tiny to begin with. Assuming no other scaling is in effect, that will be one whole pixel and a blurry pixel above it on the screen.
You're probably seeing a bug that I ran into myself: On entry into drawRect:, the current context's text matrix was not the identity matrix. In my case, I saw it contain a scale by 13 on both axes, plus a translation. (Possibly left over from drawing the title bar.) I filed this in Radar as #10585106, in case you want to file your own and cite it.
The solution is to set the text matrix back to the identity transform before trying to draw text.
Once you do that, you'll find that your text will be exactly as tiny as you asked for it to be. You should change your font size to something more reasonable; Core Text contains a function to get the system fonts (from which you can get their sizes), and AppKit's NSFont class contains methods for the same purpose.

Unstyled DIV with VIDEO child has higher height than it should

For some reason a basic unstyled DIV element has extra height tacked onto the bottom when it contains a VIDEO element (and possibly other elements - I haven't tested with many types).
<div><video src="my_movie.ogv"></video></div>
I have the above line of code in a barebones base HTML file. With Firefox or Safari/Chrome's (if I use an .mp4 file instead of course) DOM inspectors on I see that the computed height of the DIV element is anywhere from 2-5 pixels more than the height of the VIDEO element.
This doesn't seem like expected and intentional behavior. If I put a P element in there instead of a VIDEO element, for example, the DIV doesn't have any of the extra height.
Does anyone know why the browsers are rendering this configuration of DOM elements in this way?
If your markup is as above and there are no special styles applied to it, then the behavior you see is required by the CSS box model; the space is the size of the font's descent, because the bottom of the video is placed by default on the baseline, not at the bottom of the text. In particular, see https://bugzilla.mozilla.org/show_bug.cgi?id=22274#c55 for an explanation in spec terms and https://bugzilla.mozilla.org/show_bug.cgi?id=22274#c37 for how to get rid of the space if you want to. You could also set line-height on the block to 0 to get rid of the space; which approach you take should depend on your other design constraints.

Resources