How to create and immediately be able to use spritefonts during runtime? - xna

I'd like to know if it is possible to select a typeface, font size and be able to use it right away during runtime in an XNA application.
If it isn't possible using built-in runtime methods, maybe it's easier (or better, or faster) to do it using some automation software (like autoit) to create spritefont file in the background, and be able to use it afterwards in an XNA app without restarting the app?
I'm going to use this mainly on my own computer for testing and picking fonts, so I'm okay if it requires full VS installation along with XNA framework and any other stuff.

Easy put, it can be done, but you have to use WinForms, link to tutorial in order to load spritefonts. You could do it simpler, by making a couple of spritefonts before you do anything (or create spritefonts for every font you have and add them to the content). This is so, because of how XNA handles spritefonts. As you've seen, SpriteFonts are basically an xml file. This is not how the final binaries are. The final binaries are images containing every character in the font you selected at that size. That way, the gamer doesn't have to have the font installed in order to play your game, and therefore you can do some awesome stuff with fonts and the user can't use that font (unless he rips it).
I have not yet found a tutorial for winforms and spritefonts, but I suppose that the model version needs only a little modification for it to work with spritefonts.

Related

Java: How to open a library?

I want to open libraries, because currently I want to see the algorithms used for drawing, modify them and implement them in my program. For example: I have tried to create an algorithm on my own for lines. But I failed. And even if I had succeeded, I fear that it might not give the same result as the algorithm in the libraries. And I don't want this to happen. That's why I want to copy the algorithms used for the methods in libraries. And I really hope that this will help me create the application I'm currently working on and with other applications in the future.
I tried to open the libraries with a code editor. But I had troubles finding the libraries- I don't really know where are they placed nor in what files are their codes stored.
How to open a Java library? Or is there a place in the Internet where the code is uploaded?
It sounds like what you want is to get inside the standard Java libraries (so you can see the code for methods like Graphics.drawLine()).
You can download the source files from the same place you got the JDK, if you are on Windows or Linux. For the Mac, see this question. You can even set up Eclipse so that you can debug into that source as if it were your own code.
However, you will probably not find line-drawing code in Java in these libraries - the Graphics implementation will almost certainly use native methods, and may just call existing methods in the OS.
If you are specifically looking for line drawing algorithms, another option would be to look at the Wikipedia page for the Bresenham (aliased) or Wu (antialiased) algorithm.
Edit:
The part of a Graphics2D call that actually puts pixels on the screen is probably inside a system call and therefore the source would not be available.
A java vector graphics library like Batik might have source for some of these algorithms, but probably relies on the Graphics2D calls for most of them. So, you might look for a comprehensive vector graphics library written in a language other than Java, where those graphics calls do not already exist by default.
Alternately, checking the table of contents for a computer graphics book might point you at a variety of algorithms that you could look up on Wikipedia.
For any given library:
Make sure to obey all licenses when using another's code
If you are referring to the Java SDK source code, you can find it here: http://grepcode.com/
If the project is open source, you can usually just get the source from the project website. No problem, though make sure to obey their license.
If the project is NOT open source, well, then you're in a pickle licensing wise, so I do NOT endorse this, however, you would need to use a Java Decompiler such as JD-Gui
As far as what drawing algorithms to use, there are so many different ones (obviously, people have been trying to draw quickly for many many years), your best bet is to figure out exactly what you need to do and then search for that specific need separately. There isn't really a good repository of ALL of them, except maybe wikipedia.
If you are using the libraries they are on your classpath. Check out how to figure out your classpath in whichever IDE you are using and you can find the JARs you depend on. If they are packaged with sources all you need to do it unjar them and look at the sources.
If you don't have access to the sources you can get the code using a Java Decompiler.
If you are trying to look at a standard Java library, see the other answers about getting the source to the JDK.
If you are interested in an open source library (such as something maintained by the Apache project), look on the site of the project for a 'source jar' which you can open with a standard zip utility.
If the library you want is not open source or you cannot find the source for it, you can try to decompile it. If you are using Eclipse, try this decompiler.

Can i use XULRunner to create executable that acts like a phonegap app (WebView and fullscreen?) on the desktop (Windows/Linux/OSX)?

Story:
I have written a HTML Merge Compiler that can merge resource's/assets into one single HTML file (minify it to the max) and compiles Javascript with the google enclosure compiler. I have written this compiler to speed up loading and interpreting the code and to obfuscate the code to protect a little bit (script kiddie protection). Major reason was/is speed and to make it compact.
This is working OK with reliable results and i use this in PhoneGap applications/games. I have also written a javascript library that encapsulate all platforms that works with standard HTML/CSS without the need to change the code, it works also in the browser, with a touchscreen or without or on any device or operating system. Write once, publish many ;-). The idea around it is that is working always, always operate the same but can use device specific things when available but does never fail (when something is not there, for example a vibrate functionality).
Anyway, most frameworks (like PhoneGap) concentrate on Mobile Platforms but i want to port it also to desktop platforms like Windows, OSX and maybe Linux. For Windows I have wrote an Delphi Application that loads the HTML in a TEmbeddedWB object (is Internet Explorer actually) but the 'problem' is that it is only suitable to Windows and IE is not the fastest browser around, especially when it is embedded (do not why it is slower than the browser itself). For example, when i load the compiled code in Firefox and/or Google Chrome it is blazing fast (you do not notice it is javascript ;-)).
EDIT:
Pre release of IE10 for Windows 7 is just launched, installed it and lag is gone!
You can download it from here:
http://www.microsoft.com/en-us/download/details.aspx?id=35709
Introduction to my question:
I have tried XULRunner of Mozilla a long time ago but the first time was not a pleasure to me and also i tried it today again but can't get it to work. Get a parse error in the main xul file of the project, window is an undefined entity. ??? I create a sample project like: http://mdn.beonex.com/en/Getting_started_with_XULRunner.html
I do not know what to do about this error. Also i think documentation is not up-to-date? Most documentation is from around 2006.
The question, what i want to know:
Before i am going to waste my time (see also introduction), is it
possible to create frameless (full-screen) desktop executables with
use of XULRunner like with PhoneGap?
Is it possible to create cross-platform applications with XULRunner, i mean, does it really work seamless. Where can i find a ready-to-publish example of a XULRunner project and is it possible to load local HTML file(s) like in PhoneGap?
It is possible and allowed to access external resources?
Long story, but maybe there is somebody that have tried this before and can lead me to choose the right direction.
is it possible to create frameless (full-screen) desktop executables with use of XULRunner like with PhoneGap?
Yes. You use disablechrome attribute to remove the window frame and sizemode="maximized" to have it open full-screen. Alternatively you can use the full-screen API if you want your application to run in a normal window and only switch to full-screen mode on request.
Is it possible to create cross-platform applications with XULRunner
Yes. There are things like menus that work very differently on OS X but most of the time you don't need to care what operating system your application runs on (Windows, Linux and Mac OS X supported).
Where can i find a ready-to-publish example of a XULRunner project
See documentation for a XULRunner application example. For "ready-to-publish" you would need an installer which doesn't come with the platform.
is it possible to load local HTML file(s) like in PhoneGap?
Yes. The top-level window has to be XUL but you can use some very minimal code here - essentially a single <iframe flex="1"/> tag. You can load HTML pages into that frame then.
It is possible and allowed to access external resources?
Yes, XULRunner applications have full privileges and can access files on disk as well as web resources without any restrictions.

Seeking framework or skeleton for stanard desktop applications

Every application seems to start with me taking a similar app, thowing out the "meat" of it and using the skeleton for my new project.
I don't always get all that I want from a previous project, nor do I need everything from it, but certain things keep cropping up again and again:
about box (with contact email being generated from the app name & version number direct from the project options)
splash screen (source & duration)
only allow single copy to run
prevent task switching
acccept dropped files?
minimaize to tray
hide from task manager
recent files list
that sort of thing.
I used too have such a skeleton for C++ Builder, years ago. It just read an .INI file and customized the app's behaviour accordingly.
Before I take the trouble to port it to Delphi, does anyone know of anything similar which is freely available?
You can simply create your skeleton project and add it to the repository (IDE menu Project\Add to Repository).
If you want to be able to dynamically create different projects based on some parameters (user input) you can also write a wizard using the OpenTools API.

Any good PDF export filter that works with Fast Report?

I recently discovered that the PDFs exported by the Fast Report's PDF export filter aren't displayed correctly in Mac OSX, iOS and Android devices.
Fast Report informed that their pdf implementation only support Windows and they can't say when the new implementation that they are working on will be available.
I also tried to use the Gnostice export filter, but their demo installer didn't work in Delphi XE and when I contacted them, they took 15 days to send me some attached dcus which also didn't work. So I'm searching for another option.
If you know or use a PDF export filter which works with Fast Report, please let me know.
November 2015: Fast Report now have PDF/A support, with this option enabled the PDFs are fine on all platforms.
October 2014 - Fast Report 5 still seems to generate "Windows-only" PDF. A production-ready solution for this problem would be a benefit for cross-platform developers, given that Fast Report is the report generator bundled with Delphi.
Here is a fresh example generated with the Fast Report 5 demo, displayed with Adobe Reader 11 on Android 4.4:
And on Windows:
Fast Report informed that their pdf implementation only support Windows and they can't say when the new implementation that they are working on will be available.
I'm not sure that should be taken literally, considering PDF is supposed to be a cross platform format. It more likely means they don't actually have the time, equipment or expertise to test with those platforms. The PDF export filter that I'm using is the one built into Fast Report! It surely has some bugs, but I managed to work around them. And I think that might also work for you: Start with a simple document that does export properly, start adding features until it brakes, then you know what brakes it and you'll know how to work around the problem.
From my experience, here's what got me into trouble:
Rounded corners in the PDF document didn't look like the ones in the Fast Report preview. My fix: Found a combination of settings that made the exported PDF look exactly like the preview document. For me rounded corners were just a cosmetic feature, and with cosmetics there's no "One Look"; The alternative worked just fine. This might actually be fixed in the most recent version, but I didn't bother changing the document to test.
Transparency issues and outline issues. When working with the Fast Report editor (and when looking at it's previews) it's easy to overlap objects. You don't see this because of the object opacity. When exporting to PDF overlapped objects somehow managed to "print" outlines, and it obviously looked ugly. My fix: pay closer attention to those objects, make sure they don't overlap or make sure they don't generate outlines if no outlines are supposed to be seen.
Also make sure you test using ADOBE Reader, on any of the given platforms. If it works with the Adobe reader but doesn't work with other readers, there might be a bug in the 3rd party reader!
Edit: Here (link) is a sample PDF document generated by my Fast Reports application. I have no idea what kinds of documents you generate, but in my book that's a mighty complex document. Notice the diagonal line that starts where the table data ends, notice the embedded images (bar code, stamp, signature).
I opened that document on the following mobile devices:
iPad, running iOS: The document renders 90% ok. Images are not rendered at all, but they're not important to my document (and that's very likely a problem with the iOS reader). All the fancy colored lines and rounded corners are properly rendered. Some text is not properly rendered, and I'm pretty sure that didn't render because the "box" that contains it is too small for the contents. That most likely happens because I didn't embed the TTF fonts into the PDF and the Apple font on iOS didn't perfectly match the Microsoft font that was used on Windows.
Samsung Galaxy S2, running Android 2.3: The document renders 100% correctly.
Samsung Something(??), running Windows Mobile 6.5 and the FoxReader: The document is totally gibberish: pictures showed up but the spacing between letters was messed so bad it's impossible to read. I blame the reader, it's not Acrobat and it probably wanted to be "smart". And it broke it's teeth in my text encoding, because my text is not English.
About the PDF format: A document is "PDF" if it conforms to the standard, here's some Wikipedia info on that. In theory a PDF document should render exactly the same way any way you look at it, but there are forces at play that might work against this:
Not all readers are "Adobe Acrobat". In theory they're all compatible, in practice they're most like not 100% compatible.
PDFs that don't embed fonts depend on the fonts available on the host system. If they're not the exact same fonts there's trouble ahead, because they might have slightly differing sizes. Since we're talking about PDF's that were generated on Windows and opened on iOS or Android, those are obviously different platforms and they're guaranteed to use different fonts (because fonts are licensed, and I doubt Microsoft will licence it's fonts to Apple. I also doubt Apple would want Microsoft fonts). One possible solution is embedding fonts, but that makes your PDF files significantly larger.
AFAIK you can export your Fast Report pages as metafiles (i.e. vectorial Windows format, which is in fact a raw serialization of GDI commands).
Then you could be able to render those metafiles into PDF using our Open Source SynPDF library. It works from Delphi 5 up to XE, is Unicode ready, can embed true type fonts, and even create PDF/A files.
It is also able to export metafiles included in reports as vectorial pictures (and not bitmaps), and could therefore highly increase the pdf quality and at the same time shrink its size.
See for instance how it can be used for QuickReport. A similar technical should be used with Fast Report.
The Gnostice support answered my e-mail which I reported that their trial installer didn't work and send me some tips about which could be the problem and I was able to install it.
The company I work for already bought me a license and I already replaced the Fast Report Export Filter, which was a task as simple as droping 2 components on the same Form as the frxReport Object and setting 2 or 3 properties.
Also, to export the report programatically was also 2 lines of code and the information was easily found in their FAQ.
In the end, based on the recomendations and after looking for other options just to find abandoned components which doesn't have any updates for years, the Gnostice eDocEngine was the best solution.
Just hope they make their installer a little more "Programmer Friendly" as if it had complained about the lack of Fast Report's units in the search path I would've been able to at least have an idea of what was going on, instead of just getting an error and blaming them for having a trial installer which didn't work.
After replacing the filter and generating the PDF's using the eDocEngine component, the PDFs now work the same in iOS, OSX and Android.
Here is my workaround solution. It's not an universal one, but helped me in my case.
The main idea: use in report font with small file size (I've found Arial-like font with cyrillic charset with size 57kb). So the exported files can be 100-200 kb.
Details is here:
http://dev-doc.blogspot.com/2013/03/fastreport-4-font-reading-and-huge-file.html
I use wPDF from WPcubed components, it's really a great product, good value for money
You can always install one of the PDF printers. These are in fact PDF convertors that install as windows printer. They work from any application including FastReprt components - just print on them.

Tools for prototyping iPad applications

I would like to build a GUI prototype for an iPad application. The prototype can use static data (e.g. an xml file) but should look good and be fully functional, i.e. support user gestures, etc.
Obviously, I can program it in Objective-C. I wonder if I can use any other tool to build such a GUI easier. Does such a tool exist ?
Maybe I should use a GUI builder to build a "static" GUI and add some Objective-C code to make it react on user gestures. Does it make sense ?
You could use Antetype
It ships with various look and feels including ios and Android.
Balsamiq: http://balsamiq.com/

Resources