Recover obfuscated/compressed font from an epub exported from InDesign - android

I've been trying to recover some fonts from an epub created with InDesign. I tried both Adobe and IDPF algorithms (I used this source). I tried obfuscating and undoing it with a font outside InDesign and it worked.
In my searches I found out that InDesign compress the fonts. What I wanted to know is how can I uncompress theses fonts in android. I tried using InflaterInputStream to uncompress it, but with no sucess causing a
IOException caused by: java.util.zip.DataFormatException: data error
I tried this approach because the font inside the epub file has 11kb and the original font has 253kb.
Well, tried to be as clearer as I could, any doubts please ask.

One piece of information that may be helpful is that InDesign CS5 now subsets fonts that are included in epub documents. The 253kb to 11kb size difference may simply be compression, but it seems somewhat unlikely.
So you may find that, even after extracting the font, it is not very helpful to reuse as it will be missing key characters that were not used in the ePub.

Related

Android: add some Chinese characters [duplicate]

I want to use #font-face to import a chinese font into my site. But as we all know chinese fonts are always large.
Since i will only use no more than ten chinese characters one time, i wonder how can i extract several characters from a chinese font?
Tks~
You can use the FontSquirrel web tools to do this: http://www.fontsquirrel.com/fontface/generator
Expert
Subsetting: Custom Subsetting
Single characters
Other than online uploading solutions, there are also offline editors like Fontforge that can do the same task.
For instance you can look at this guide for Fontforge which do the same task.
The main reason why this could be preferrable over online solutions are that, other than more customizable subsettings, there are also no file size restrictions in doing the extraction process locally. It is rather common for Chinese fonts especially for those with large collection of glyphs.

Android: How to load a vector drawable image into a webview?

Sorry if this is a repeat but I searched diligently and didn't find this question asked yet...
So back in ye olden days of Android, you could just add something like this to a WebView's source html:
<img src='file:///android_res/drawable/my.png'/>
And it would display my.png correctly in the WebView. But-- Android now supports (and prefers we use) these new-fangled vector drawables, and Android Studio's Vector Asset Studio makes it really easy to import them from SVG files or whatever.
The great thing is that for backwards compatibility, .pngs are automatically generated during the build for various dpi/screen sizes to support older devices. So if you're targeting an older device, there are .png images there.
If only I could reach them. Because, as far as I can tell, using vector graphics does break those file:///android_res/drawable/ img links in WebViews. Which is weird, because as I say there are .png files to see, if it only looked.
I've thought about a few methods to fix this, but none have worked:
Since .pngs are generated on-the-fly and are included in the .apk, I thought maybe I could point directly to one of the generated files with something like file:///android_res/drawable-hdpi-v4/my.png. (I checked the .apk file and that's where one of them was..) But no such luck there. Broken image.
Okay, I thought-- maybe there's a way to get the WebView to display the vector objects directly. That is, maybe the WebView would recognize an <img src="file:///android_res/drawable/my_image.xml"/> or something similar. I mean, Chrome can render svg right? Maybe it supports the .xml vector format too. But no dice here either. (Even if it had worked, it would be unlikely to support older pre-chromium webview versions.)
The third thing I tried is to include just one xxxhdpi-sized .png in res/drawable so that the webview would find it and hopefully display it. Unfortunately, this doesn't work either. It appears that just having an .xml vector in /drawable is enough to have it block the png, no matter if it's in the /drawable or /drawable-xxxhdpi directories.
So the obvious question: Is there a way to get the WebView to either display the vector xml (or the associated support .png that was generated)? How do we access drawables from HTML in a WebView w/Vector drawables? Esp. without having to do anything programmatically?
Anyone know how this is supposed to work? I guess the next thing to do is delve into the chromium/android source to try to find out how file:///android_res/drawable/ works, but that doesn't sound fun, so if anyone has an answer, that would be helpful.
I'm probably missing something really obvious here. Thx in advance!
Update: Other things I tried/ruled out include (1) removing underscores in image names (as I thought they might be replaced with "/"), (2) various permutations of baseurl in loadDataWithBaseUrl()
Well, four years later and the best solution I've come up with is just to have two vector files-- (1) the xml Android vector file for the app, and then (2) the identical image in the .svg format for the webview. This is still a smaller solution compared with providing a seperate .png or .gif for every dpi, etc.
SVG and the vector format are internally very similar, so it's not difficult to convert one to the other. In fact, Android Studio will convert SVG->XML. If you want to go the other way, just compare a few examples.
So just put your svgs in assets/svg/, and then you can access from a webview using <img src='file:///android_asset/svg/mysvg.svg'/> in your HTML.
There's still a storage hit. But svgs are relatively tiny (and you can minify-- ie, scoop out some of the extra fluff in the SVG file that isn't used by the webview) so it's not as bad as the alternative-- providing large binary image files in the apk.

Tesseract character recognition problems in Android (but not on iOS?)

I've build an application that uses Tesseract (V3.03 rc1) to identify some specific text strings. These are, unfortunately, printed on a custom font that requires that I build my own traineddata file. I've built the application on both iOS (using https://github.com/gali8/Tesseract-OCR-iOS for inspiration) and Android (using https://github.com/rmtheis/tess-two/ for inspiration as well).
The workflow for both platforms is as follows:
I select a bounding box on the preview screen for where I can crop out the relevant text, and crop the image accordingly.
I use OpenCV to get a binary image (using OpenCV's adaptive threshold function with the same parameters for both platforms)
I pass this binary image to Tesseract. Both platforms (Android and iOS) use the same traineddata file.
And yet, iOS recognizes the text strings perfectly, while Android keeps misidentifying certain characters (6s for Ss, As for Hs).
On both platforms, I use the same white list string, I disable load_type_dawg and load_system_dawg, and also choose to save the blob choices.
Has anyone encountered this kind of situation before? Am I missing a setting on Android that's automatically handled in iOS? Is there something particular about Android that hasn't crossed my mind?
Any thoughts or advice would be greatly appreciated!
So, after a lot of work, I found out what was wrong with my Android application (thankfully, it wasn't an issue with Tesseract at all). As I'm more familiar with iOS apps than Android, I wasn't sure how I could load the traineddata file onto the application without requiring the user to have the file loaded on their external storage device. I found inspiration in this project (http://www.codeproject.com/Tips/840623/Android-Character-Recognition), as they autoload the trained data file.
However, I misunderstood how it worked. I originally thought that the TessDataManager did a file lookup on the project's local tesseract/tessdata folder in order to get the trained data file (as I do this also on iOS). However, that's not what it does. It, rather, checks the internal file structure (data/data/projectname/files/tesseract/tessdata/traineddatafilegoeshere) to see if the file exists and if it doesn't, it copies over the trained data file it keeps in the Resources/Raw directory. In my case, it defaulted to the eng file, so it never read my custom font file.
Hopefully this helps someone else having similar issues. Thanks to Robin and RmTheis for all of your help!

Unknown JPEG compression technique?

Well, so I've been digging through an android game's files trying to get sprites and the like. So I've managed to come across this folder called "raw", and inside were jpg files like imagelocal2.jpg (along with imagelocal2.list) and such. These files aren't valid images and can't be viewed normally, but they're big enough to contain many images inside of them.
What I'm wondering is, is there some unknown JPG compression-like method where they manage to squish a bunch of files into one? I opened the files with a hex editor but I couldn't make heads or tails of them (the fact that I have no experience with hex editors doesn't really help), so if anyone knows anything about how these files are compressed, please help.
There is no standard multi-image JPEG format. it would be anything with a JPG extension. No competently-written decoder would rely on the extension anyway.
You could take a look at the first few bytes and try to match the file signature.
http://en.wikipedia.org/wiki/List_of_file_signatures

Avoid XML convertion in .apk to .apk.zip in android

I create an application in android.
I know .apk can convert into .zip and my layout and xml files are extracted.
Is there any way to avoid the decoding of xml?
How can i encode the apk so it cannot converted?
thanks
An .APK file is simply a .ZIP file with a predefined directory/file layout, there is no "conversion" (unless you're simply talking about changing the extension).
ProGuard can be used to obfuscate code, but there's no "standard" way of encoding/encrypting the XML files. You could encrypt/decrypt them manually yourself, but you'd be introducing a great amount of overhead at runtime for decryption, and many standard interfaces would not work because they expect the standard plan-text XML format. You're looking at a great deal of code to accomplish what you're asking. This is all assuming you're loking to encrypt your strings.xml, etc.
If you're looking to encrypt custom XML data files, there's a thread with some good suggestions here.

Categories

Resources