hanzi-writer
hanzi-writer copied to clipboard
Possibility of loading SVG directly, or creating local .json using SVG?
Thanks so much for updating the documentation. With the new docs I was able to get everything working, and even get it embedded inside Anki. Great excitement.
I have access to high quality SVG data for rare characters and variants through Wenlin, and was curious if there was any way I could use SVGs exported from there. Any idea how I could take an SVG and use its stroke data to create an object suitable to use with Hanzi-Writer? I'm guessing half this question belongs on Make me a hanzi, but any help you can offer would be appreciated. I'm working on using Hanzi-Writer inside Anki and am most of the way there. I'll be releasing my work once I clean it up and get the full functionality I'm after. One big one is this need. I'm hoping to eventually be able to set things up so people can export SVGs from Wenlin or retrieve them from other sources, and be able to set up a HW quiz for them in Anki easily. Wenlin even has some unwieldy scripting, so my ideal end goal is I can set things up so people could simply run a couple scripts and generate HW flashcards from it provided they have the rights.
I've had a look at the data format and it seems to be basically normal SVG stroke data just very slightly different. I also don't understand what the "medians" property is all about, and can't seem to find any clear information on this.
Any help appreciated.
Inside Anki !!! :heart_eyes:
Then...
- I'am not the expert in HanziWriter - Wenlin technicallities, so better answer than mine may come.
- ... but did you first checked out Wenlin's license ? I don't think you are allowed to extract and reuse their data. (I would be surprised if we can!)
- You may as well contribute to MakeMeAHanzi for the needed characters.
- When you share your project on GitHub, please list it on the wiki https://github.com/chanind/hanzi-writer/wiki
That's awesome to see this embedded in Anki! That's so cool!!
As for using Wenlin data, I worked on a similar hanzi-writer-esque project with Wenlin here: http://wenlincdl.com/. You could directly use that project if you want to embed Wenlin data into Anki in a similar format, but it's not free, and like @hugolpz said they're pretty picky about licensing. Make sure to contact them to ask about licensing if you want to release your project beyond just your personal use. The easiest method might be to use Hanzi Writer for when there's data available, and fallback to using the Wenlin CDL js library for when there's not.
I've had a look at the data format and it seems to be basically normal SVG stroke data just very slightly different. I also don't understand what the "medians" property is all about, and can't seem to find any clear information on this.
Medians is the animation path of the stroke. So the SVG pathstring defines the outline of the stroke, and the medians is how the path is animated. Medians is from Make me a Hanzi too. The way the Wenlin JS library works is it uses the Wenlin Plain font as the median points since the plain font is just a non-closed set of points that can be used for animation. If you wanted to use Wenlin font data in Hanzi Writer, and Wenlin is OK with it, you would need to scale the Wenlin character SVG to fit into a box with the upper left corner is at (0, 900)
and the bottom right corner is at (1024, -124)
to match Make me a Hanzi's format, and use the Wenlin plain font points as the medians. But again, you may as well just use the Wenlin CDL JS library in that case since it will do all this for you.
Woah that's awesome. I had no idea about CDL js even though I spent a lot of time searching for something like it (I looooooove CDL). Obviously if I can go straight to using the CDL without the need to export SVGs manually, that would be ideal. I'll have to look into it.
Yeah, use rights are tricky things. My assumption is that I won't be able to actually package any data from Wenlin, just give people the tools to generate it for personal use. But even then, I'll definitely have to check what the terms are, because that stuff can get weird. Academic organisations and software providers both tend to be funny about their IP.
Thanks for demystifying the data, I suspected it was something to do with the stroking.
Either way, whether I go with SVGs or move over to CDL js, I'll be sure to give you guys an update.
I need Hanzi-Write anki implementation in my life!!!
If you have anything usable I would be very interested in trying it out. I'm from the US currently studying Mandarin in Shanghai. I use Anki everyday, and really want hanzi-writer quizzes on my cards that test writing.
Amazing work!
I've managed to get it working reliably, however it's just treacle slow, and grotesquely slow on mobile where it becomes borderline unusable from speed issues alone. I haven't had the time to work out if it's something I'm doing, or an inherent problem in HanziWriter, or indeed a fixable one. It's slow on both Anki 2.0 and 2.1 beta atm, so it's a real puzzle indeed. We'll see what I can do in a few weeks as the holidays are coming up. I might try a rewrite of what I did, just to see if anything changes. If I can't get it working before my holidays are up I'll just release what I've done either way, but I'd rather give people something that's somewhat usable and somewhat clean. Hope the wait doesn't kill us both :D
@NinKenDo64 : what tech do you use ? All HTML-JS-CSS or you take over the XML and redo some stuff ? On which "Anki" code/app do you plug your code ? Can you share some basics specifics to light up our brains :D ?
My current implementation is purely HTML/CSS/JS. Which is also messy as a dog's breakfast in Anki 2.1 atm because I can't get it to reference out to external files (CSS is fine, but nothing else). Also just requires some pretty hacky solutions of invisible divs and stuff. I'm currently away from home atm, but when I get back I might just throw up the mess I have atm so you guys can have a squiz if you're interested. It definitely works, but a more low-level intervention might be necessary to get it working well.
If i understand you load the xml data via your local js file right ? So speed should be good. I remember a huge HSK deck with 8800 mp3
working normally fast. Anki decks can store .mp3
files efficiently, should be able to localy store and query .xml
or .json
files i guess. This specific sub-issue could be better to deal with within the Anki community.
I'd be curious to experiment with the performance issues if you can get a demo up. It's possible the JS / HTML environment Anki uses isn't super optimized for things like SVG animation and JS performance.
Referencing external files should be no problem in Anki. I've seen external JS files referenced using @ before. The file reference just needs to be in Anki's media directory.
This is actually done in the deck closest to what I want. It's basically like hanzi-writer but no matter what I do I can't get it to work for more than one character words. Anyway check out this deck if you want to see how to reference and external file and also how to elegantly implement a canvass for practicing hanzi in Anki. There are likely many clues to in this deck and on the website linked below to help with getting hanzi-writer to work.
link: http://abananablog.com/2016/12/31/anki-trace/ not sure the link works but the page came up first when I searched the internet for: "mandarinbanana write chinese anki"
I think the hanzi-writer platform is superior than what's in this deck so I hope y'all can get it working somehow. I really admire all your skills and efforts. Thanks.
Was any progress made on this plugin for anki?
I wrote a Anki 2.1 plugin, you can find it under https://github.com/Rentier/anki-maobi
Check this for Anki Implementation https://github.com/infinyte7/Anki-xiehanzi