I'm working with flex 4 and need to export some pdf files. I'm useing purePDF library for this. Can anyone explain me how to make possible to write romanian characters in pdf files with purePDF -> I need to write characters like ăîşţ, etc.
I look in the wiki documentation of that library but cannot understand enough what I need. Appreciate any help.
Thanks
I'll ask my own question, taking in consideration that it'll be useful for other one.
Note: Taking in account that purepdf is the iText library equivalent from Java, when you encounter any problems and need documentation, you can consult iText documentation for inspiration with purePDF.
So this is what you need to do:
find a suitable "True Type" font that contains your special characters (with "ttf" extension). For me, I found that in the /usr/share/fonts/truetype/*.
copy the *.ttf font file in a directory for use in your application (in my case "assets" directory)
after you find that, you can try it if matches your needs by the following code :
public static const SERIF_NORMAL : String = "FreeSerif.ttf";
//"assets/fonts/FreeSerif.ttf" is the directory where I copied my *.ttf files
[Embed(source="assets/fonts/FreeSerif.ttf", mimeType="application/octet-stream")]
private var serifNormalCls : Class;
private var normalFont : Font;
var bfNormal : BaseFont;
//...
//in youre initialization function :
FontsResourceFactory.getInstance().registerFont(SERIF_NORMAL, new this.serifNormalCls());
bfNormal = BaseFont.createFont(SERIF_NORMAL, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
//and when you need to use your the special characters, you will use that font
this.normalFont = new Font(Font.UNDEFINED, 10, Font.UNDEFINED, null, bfNormal);
Cheers!
Related
I have recently picked up flixel (I have programmed before, but I have not in a while) and I have come across a problem. I am attempting to create maps, and eventually there will be multiple maps available.
I currently have a .txt file that has information that eventually goes into an array. Then I go from array to map with loadmap. It is maybe a simple way to accomplish this task, and maybe their are better ways (I have not explored all the possibilities with flixel, and if there are any opinions, go ahead and let me know) but it works good for now.
As I have previously said, I am trying to do this with multiple maps. I could do this by using [Embed(source = "")] for each .txt file, but this may end up being annoying. So, here is my question: Is there a possible way Embed a file based upon a variable?
My Map class looks like this:
public function Map(MapSet:String, TileSet:String)
{
super(MapSet, TileSet);
//more stuff
}
Now I have tried:
[Embed(scource="data/MapSets/" + MapSet + ".txt", mimeType = "application/octet-stream")]private var loadedMap:Class
and then I use:
map = new Map("Map1x1", "ForestTiles");
add(map);
Is there a possibility of doing this in a different way? Or maybe I am doing something wrong? All opinions are welcome.
It's beneficial to know what code does when using it.
Embed is a meta tag. It tells the compiler to include a certain file into the .swf file.
That means this does not happen at runtime.
When this embed code is "executed", your variables don't even exist yet.
That's why your code cannot work.
Despite not working, your solution is still valid:
If you find it tedious to generate code, write a program that does this for you. Create/use a program that finds all valid files in the given directory and creates all the embed tags. Run this program before the compiler.
To embed a text file and use as a string, try this:
// create source var TextSource
[Embed(source="textFile.txt",mimeType="application/octet-stream")]
private var TextSource:Class;
var myByteArray:ByteArray = new TextSource();
var myString:String = myByteArray.readUTFBytes(myByteArray.length);
// then use for your function
map = new Map("Map1x1", myString);
My app runs in WPF and Android (Windows Phone later) with mvvmcross as framework. I implemented localization with JsonLocalisation like the Babel (N21) example and it is working fine in Android. But whatever I try in WPF I get this message;
mvx:Warning: 0,22 Language file could not be loaded for Danish.SettingsViewModel -
FileNotFoundException: Unable to find resource file MyAppResources/Text/Danish/SettingsViewModel.json
at Cirrious.MvvmCross.Plugins.JsonLocalisation.MvxContentJsonDictionaryTextProvider.
LoadJsonFromResource(String namespaceKey, String typeKey, String resourcePath) at >Cirrious.MvvmCross.Plugins.JsonLocalisation.MvxTextProviderBuilder.LoadResources(String >whichLocalisationFolder)"
Stuart says in his video tutorial that the json translation files must be included as "Content" and not copied to the output folder - like;
But looking at the compiled executable with "dotPeek" doesn't reveal the files.
Am I missing something obvious? Any hints would be highly appreciated. Even confirmation from somebody who has JsonLocalisation working in WPF would be nice.
EDIT:
Well, I tried this code in my WPF mainWindow. I understand this call is used internally in MvxWPFResourceLoader.
public MainWindow()
{
....
//This return null without exceptions.
var t = Application.GetResourceStream(new Uri("MyAppResources/Text/Danish/SettingsViewModel.json", UriKind.Relative));
//This throwns an IOException; Cannot locate resource 'thisdoesnotexist/text/danish/settingsviewmodel.json'.
var y = Application.GetResourceStream(new Uri("ThisDoesNotExist/Text/Danish/SettingsViewModel.json", UriKind.Relative));
}
It seems when the path if wrong an exception is thrown. When it is correct it just returns null!!?! I am a bit puzzled, any ideas?
Best regards
Thank you for such fast answer (and for mvvmcross!).
The link you provided is to a Babel solution with a WPF sample - exactly what I needed. I mistakenly used the one from N21 without WPF sample :-)
Anyway, when looking at the sample I noticed that the json files must be included as 'Resource' and not 'Content'. That made all the difference - hurray!
Best regards
I recently found Mike Chambers' as3corelib when looking for ways to render the stage to a file. Works great in my ActionScript 3.0 project in Flash Professional (CS6 if it matters).
I decided to look at some of Mike's utility classes, notably the date related ones. However, his DateUtil class imports mx.formatters.DateBase, and when I attempt to use some of the methods, I'm getting lots (and lots) of "Access of undefined property DateBase."
I'm assuming that's because some reference to the Flex SDK is missing or wrong. I've added $(FlexSDK)/frameworks/libs/flex.swc to my project's Library path, but that's not helping.
I've used Flash for years, but this is my first truly code-centric project, and still learning through the school of hard knocks. No idea what's going wrong here. Ideas?
Example from as3corelib
package com.adobe.utils
{
import mx.formatters.DateBase;
/**
* Class that contains static utility methods for manipulating and working
* with Dates.
*/
public class DateUtil
{
/**
* Returns a date string formatted according to RFC822.
*/
public static function toRFC822(d:Date):String
{
var date:Number = d.getUTCDate();
var hours:Number = d.getUTCHours();
var minutes:Number = d.getUTCMinutes();
var seconds:Number = d.getUTCSeconds();
var sb:String = new String();
sb += DateBase.dayNamesShort[d.getUTCDay()];
sb += ", ";
...
The line:
sb += DateBase.dayNamesShort[d.getUTCDay()];
...generates the mentioned error, as does any other DateBase reference in the class. Again, this code is directly from the latest as3corelib, located on GitHub: https://github.com/mikechambers/as3corelib
Don't know whether you got this one licked or not, but I hit the same thing. Love the library, hate the error messages.
I downloaded the Flex SDK from here:
Adobe Flex SDK Download
Then, I unzipped that into a temporary folder.
Then, since I didn't want the whole flex framework lurking about, I created a ./lib directory inside the directory where the .fla file lives. I then moved these swcs from here (Inside the unzipped file structure):
mv ~/Downloads/flex_sdk_4.6/frameworks/libs/framework.swc ./lib
mv ~/Downloads/flex_sdk_4.6/frameworks/libs/core.swc ./lib
mv ~/Downloads/flex_sdk_4.6/frameworks/libs/mx/mx.swc ./lib
Not sure why all three were required, but it stopped the compiler complaining (and got the date conversions working).
You need to add them to the .fla's library list as well (under ActionScript Settings); but I'm betting you already knew that.
Perhaps useful, perhaps not.
What would be a best Class for base64 encryption/decryption in Action Script?
Adobe has two utils for this - Base64Encoder & Base64Decoder. Both are located in the mx.utils package. Although, I had to track them down here - encoder & decoder.
The usage would be something like:
var bmd:BitmapData = myBitmap.bitmapData;
var ba:ByteArray = bmd.getPixels(new Rectangle(0,0,bmd.width,bmd.height));
var b64:Base64Encoder = new Base64Encoder();
b64.encodeBytes(ba);
trace(b64.toString());
Similarly, 'b64.encode' would encode a String rather than a ByteArray.
Both the encoder and decoder add their respective results to an internal buffer. So, you just have to use 'toString' to return the current buffer.
This one seems to have some legs/supporters: http://garry-lachman.com/2010/04/21/base64-encoding-class-in-actionscript-3/
At this link you will find a good Base64 class:
http://www.sociodox.com/base64.html
blooddy_crypto claims (according to it's benchmark) to have a faster base64 encoder/decoder than the mx.utils one.
Most of the packages that I have seen that include one as a support function use the one that is credited to Steve Webster. I do not know which package this started out in, but it appears in several libraries, including the as3crypto lib on Google Code.
Several frameworks and languages seem to have lnk file parsers (C#, Java, Python, certainly countless others), to get to their targets, properties, etc. I'd like to know what is the general approach to reading lnk files, if I want to parse the lnk in another language that does not have said feature. Is there a Windows API for this?
There is not an official document from Microsoft describing lnk file format but there are some documents which have description of the format. Here is one of them: Shortcut File Format (.lnk)
As for the API you can use IShellLink Interface
Simply use lnk file parser at J.A.F.A.T. Archive of Forensics Analysis Tools project.
See lnk-parse-1.0.pl at http://jafat.sourceforge.net
There seems no have no dependencies. Syntax is simple and link file becomes a simple text in standard output and to be usable on Linux.
This is an old post, but here is my C# implementation for lnk processing that handles the entire spec, more info and command line tool on this blogspot page.
Using WSH-related components seems the most convenient option to read .lnk files in most languages on a post-XP windows system. You just need access to the COM environment and instantiate the WScript.Shell Component. (remember that on win, references to the Shell usually refer to explorer.exe)
The following snippet, e.g. does the thing on PHP: (PHP 5, using the COM object)
<?php
$wsh=new COM('WScript.Shell'); // the wsh object
// please note $wsh->CreateShortcut method actually
// DOES THE READING, if the file already exists.
$lnk=$wsh->CreateShortcut('./Shortcut.lnk');
echo $lnk->TargetPath,"\n";
This other one, instead, does the same on VBScript:
set sh = WScript.CreateObject("WScript.Shell")
set lnk = sh.CreateShortcut("./Shortcut.lnk")
MsgBox lnk.TargetPath
Most examples in the field are written in VB/VBS, but they translate well on the whole range of languages supporting COM and WSH interaction in a form or another.
This simple tutorial may come handy, as it lists and exemplifies some of the most interesting properties of a .lnk file other than the most important: TargetPath. Those are:
WindowStyle,
Hotkey,
IconLocation,
Description,
WorkingDirectory
here's some C# code using the Shell32 API, from my "ClearRecentLinks" project at https://github.com/jmaton/ClearRecentLinks
To use this your C# project has to reference c:\windows\system32\shell32.dll
string linksPath = "c:\some\folder";
Type shell32Type = Type.GetTypeFromProgID("Shell.Application");
Object shell = Activator.CreateInstance(shell32Type);
Shell32.Folder s32Folder = (Shell32.Folder)shell32Type.InvokeMember("NameSpace", System.Reflection.BindingFlags.InvokeMethod, null, shell, new object[] { linksPath });
foreach (Shell32.FolderItem2 item in s32Folder.Items())
{
if (item.IsLink)
{
var link = (Shell32.ShellLinkObject)item.GetLink;
if (link != null && !String.IsNullOrEmpty(link.Target.Path))
{
string linkTarget = link.Target.Path.ToLower();
// do something...
}
}
}
#Giorgi: Actually, there is an official specification of lnk files, at least it is claimed so.
However, for some reason, the link seems to be dead, and after downloading the whole (45 MB) doc package (Application_Services_and_NET_Framework.zip), it appears that it does not include the file MS-SHLLINK.pdf.
But is this really surprising ?
Once you got the file format, shouldn't be too hard to write code to read it.