How do I load a custom font from an embedded file into DirectWrite in a Metro app? - microsoft-metro

I have been fighting a losing battle against loading fonts from an embedded file for use with DirectWrite. I am writing a simple puzzle game that has a C#/XAML interface but also uses SurfaceImageSource to add some DirectX content.
I have written a WinRT component that handles all of the DirectX code, and it works quite nicely. Some of my DirectX content is text drawn using the DirectWrite API. I can draw all the text I like so long as I'm loading an installed font from the system using IDWriteFactory::GetSystemFontCollection(), etc. But, I cannot seem to find a way to load a custom font from an embedded file.
From what I can tell Metro apps are not allowed to load files from the filesystem in the same way as a traditional app. So, the IDWriteFactory::CreateFontFileReference() method that takes a normal file path is worthless to me, right? I need to load my file from an ms-appx URL.
So, I wrote a custom font loader in my WinRT component that implements the IDWriteFontCollectionLoader interface (which is a ton of work if you've never done it before btw) that loads the font from an ms-appx URL using the new StorageFile API. Now, I can load my IDWriteFontFile and I can get a IDWriteFontFace, but if I try to call any of the truly useful methods on the font face it returns E_UNEXPECTED. I can get the number of glyphs and the glyph indices, but if I try to call something like GetGlyphRunOutline() or GetDesignGlyphMetrics(), it fails with E_UNEXPECTED. Using the same drawing code that generates an ID2D1PathGeometry using GetGlyphRunOutline() works great as long as I install the font file and get the IDWriteFontFace through the series of calls starting with IDWriteFactory::GetSystemFontCollection(). I am working with a normal true type font.
So, how do I load a custom font from an embedded file into DirectWrite in a Metro app? I'm probably just missing something easy, because I am certain that other people will want to be able to load custom fonts in this way.
I have a sample project (or could prepare one easily) for anyone who can help me identify my problem.
I have loaded the two IDWriteFontFace objects side by side, and I tried to figure out what is different between the one that works and the one that breaks. What I need to see in order to find out why it is failing is opaque to me hidden behind inside the IDWriteFontFace interface. HELP PLEASE!
Question also posted here: Building Metro style games with DirectX Forum

Well, the answer is... don't write a IDWriteFontCollectionLoader! You can use IDWriteFactory::CreateFontFileReference() with the StorageFile API. I was under the impression from all of the Microsoft Conference talks I had attended that in Metro you would be unable to access the native file system directly; the way forward would be to use the StorageFile API which references resources, etc. using ms-appx URLs. I understood that this was done for concurrency and to allow the OS to insulate itself from Metro apps that would be downloaded from the store by creating a file system sandbox. I think that is accurate. But, I feel like I was led to believe that we would never be able to get native file system paths. That is NOT true. IStorageFile provides a way. Just use IStorageFile.Path. I never looked at it because I just assumed the Path property would hold the ms-appx URL that I used to create the object. Microsoft probably provided this for exactly the purpose in my problem above: calling legacy COM interfaces that require a native path.
I haven't done any testing to determine whether the WinRT framework actually sandboxes you if you try to access a native file system path outside your own app package. I'm betting that it does...

Related

How to reverse engineer a progressive web app ?

I found this free PWA https://www.the-qrcode-generator.com and now wonder how I could do one such myself.
Since I couldn't find any access to its source code I wondered if it'd be difficult to reverse engineer.
I'm interested in building a PWA with QRCode functionality.
This one was created with AngularJS v1.3.20. You can find the source in your console windows under Sources tab. You can easily beautify the code inside the window to make it readable.
If you want to know how they organized their rest API, the browser network tab will help a lot, just filter by XHR and examine all the call from the front end to be.
The front end is very hard to revers engineer, because most sites are served as minified bundles, so you can't see the original code.
You can however find some other information about what they used to build it, for example in the html source you can see some ng-* tags, which indicates that this is angular, you can also see that body has attribute data-ng-app meaning this is angularjs and so on.
For the QR logic you can see that there are no back end calls, meaning that it is written entirely in the client. I would search for already available solutions for that.

How can I program a button on an Access form to link to a browser window that looks up multiple addresses on Google Maps?

My problem is very similar to the one posted here:
http://www.utteraccess.com/forum/Plotting-Addresses-Maps-t1968130.html
except that thread never found any solutions. Basically, I'm working on an Access form that has a datasheet as a subform. Upon clicking a button on the main form I'm trying to make it so that a browser window opens up and, using the address columns from the spreadsheet data in the subform, plot all the address markers listed. I've looked up a lot of ways to attempt this but I've yet to find a way that seems to work.
I'm not even sure if it's possible to plot multiple markers on Google Maps, but according to research (and after trying it myself) it seems like it isn't, although I don't want to rule it out entirely because I'm still not 100% sure. However I know both Google Earth and batchgeo.com do allow this. I still want to try and do this on Google Maps, but if that doesn't work I want to try to do it using batchgeo.com and if that still doesn't work, then Google Earth (I don't want to make the user download external software if possible).
If it helps, from what I've read API's seem like a useful tool, though I'm not sure how to apply it to an Access form, it seems more like a way to embed to already existing websites.
I'd really appreciate if someone could help me figure out how to approach this problem!
Maybe this would help?
http://ramblings.mcpher.com/Home/excelquirks/getmaps/mapmarkers
It is Excel but should be translatable.
Here is another example, this time using Access:
http://www.utteraccess.com/forum/Google-Maps-Multiple-Mar-t1973499.html
...from what I've read API's seem like a useful tool, though I'm not
sure how to apply it to an Access form, it seems more like a way to
embed to already existing websites.
You're right. There's no way, that I'm aware of, to embed a Google Maps object in a form (like an ActiveX control). Microsoft MapPoint is a software product that lets you do Map integration by way of an ActiveX control (no need to use HTML and/or javascript).
What I usually do on a project like you're working on is I get my HTML page working the way I want it to, outside and independent of MS Access. You should be able to program and test the HTML file locally without having to use an actual web server. Just use something like NotePad++ or Sublime Text Editor 2 to write your HTML and Javascript and then open the file in your browser to see if it works. I'm quite sure you'll need to use Javascript in your HTML page to make this work. That's what the Google Maps API is all about.
After you have your webpage working, then you will have to go into Access and write code to create that web page on the fly with the address data for the current data set. You can just write it out to the Windows Temp folder and then open your browser control that that web page.
Julian Knight's answer links to more specifics on how to create the HTML page on the fly. It looks like gobble-de-gook, mostly because it is. Outputting HTML/Javascript/CSS from VBA is far less than optimal. This is why you troubleshoot it outside of Access, as much as you can.

UI Automation Verify v/s UISpy - The way they find UI elements

I am trying to automate UI interactions for a C++ MFC application. I tried to find elements' automation ID using UISpy and UIAVerify tools. I am on win2k3.
There is a tab control, the automation ID of which is visible to UISpy but not to UIAVerify.
The issue is - it is not visible even to the C# code that I write using Project White framework or ui automation framework of .net 3.0.
I want to get handle to this control the way UISpy gets it. Is there any way I can find out how UISpy does it?
Thanks!!!
UISpy is likely using Microsoft UI Automation under the covers. You can see how this works from this example*. There are all kinds of conditions on AutomationElement which you can use to locate them.
I've only worked with WPF tabs, but found it really, really hard to locate them by Automation Id. Instead I've been using the AutomationName property, with the title on the tab as the value. Not sure if White supports this, but I'm pretty sure you can get the original AutomationElement out and use it as per the example.
You'll also probably be looking for something supporting the SelectionItemPattern (there's a SelectionItemIsSupportedProperty), and you'll need to use the pattern to select the tab and make it active before you can see anything in it.
Please comment if you need any more info. It might help to know what the structure of your container with tabs in is.
*Declaration of interest since I wrote this.

WebGL framework - what's the best choice? X3DOM?

I'm about to start a Web application that will use interactive generated 3D content. Aim is to let it run natively in the browser, i.e. no Flash is allowed, only JavaScript + HTML5.
Apart from using pure WebGL it's better to use a lib that will offer a more high level interface.
The approach of X3DOM looks great for me - and it looks like it's supposed to become native in the browser and the lib will pave the road.
But after my first impressions I'm not sure if it's lightweight enough. Apart from the 400kb JS-File it slows down Firefox.
The features I need are not many. The whole scene set up could be easily done by "hand". But I need user interaction including to figure out where the user clicks. And later I want to be able to load and insert 3D objects in a common file format.
PS: Browsers of choice are Firefox and Webkit based ones. Desktop and Mobile ones. I don't care about IE.
PPS: Yes, I know the question: WebGL Framework
X3DOM is great when you come from an X3D background (and developed by great people), but if you have no preference watsoever, Three.JS would be my pick.
I looked at most WebGL frameworks just last week, and it indeed seems almost every one of them is in the 300kB range. That's too heavy for me, too. Luckily I found lightgl.js which has everything you need to get started in 28kB, MIT license.
The main thing for me is just abstracting canvas, shader and texture initialization. But lightgl.js does also have some mouse handling and model loading etc.
i think the decision boils down to:
do you want to have a more design or programmer approach.
x3dom: its leveraging of x3d for describing the scene lends itself to a more designer approach, with just the adding of the x3dom css and js one can do this :
<X3D><Scene><Shape><Box/></Shape</Scene></X3d>
three.js: only allows for scene generation through javascript, and a lot of additional code is necessary just to set up the canvas. view the source of this simple box example: http://stemkoski.github.com/Three.js/Template.html
neither way is wrong, i prefer designing the scene and then using js when needed for any computations.

Using custom styles with Basic4Android

As a follow on to the hide activity questions here, I started looking through the Andoid documentation for more information on styles and themes and found it is possible to apply different themes for different API levels.
With this I can get my transparent activity on API levels that support it properly.
What I'd like to know is, is it safe to play with the styles within the Basic4Android environment, or will it comeback to bite me later on?
The xml has to be stored in res/values or res/values-v(API level) which are deleted on compile unless made read-only. I just wanted to check if this was to stop these being changed for a reason, other than keeping the app tidy?.
Edit:
I assume some things that it is possible to put in these files would overwrite or be overwritten by settings in the Designer.
Steve
I don't see any problem with using styles. Make sure to set your xml files to be read-only.
The designer doesn't change anything except of creating the bal files.