Skip to content

Commit

Permalink
all: Disabled image support by default (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
pgaskin committed Feb 21, 2020
1 parent b403da2 commit 641efd5
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
13 changes: 7 additions & 6 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,24 +169,25 @@ steps:
commands:
- git clone https://github.com/wjdp/gotdict
- git -C gotdict checkout 0a675ef59b5068a91315d594f807dc8d9ae4a777
- ./gotdict-convert -o gotdict.noimg.df
- ./gotdict-convert -o gotdict.df --images
- ./gotdict-convert -o gotdict.df
- ./gotdict-convert -o gotdict.img.df --images
- ls -lah gotdict.df
- name: generate
image: golang:1.13-buster
commands:
- apt-get update -qqy && apt-get install -qqy swig
- go run ./cmd/dictgen -o dicthtml-gt.noimg.zip gotdict.noimg.df
- go run ./cmd/dictgen -o dicthtml-gt.zip gotdict.df
- go run ./cmd/dictgen -Iremove -o dicthtml-gt.zip gotdict.df
- go run ./cmd/dictgen -Ibase64 -o dicthtml-gt.img.zip gotdict.img.df
- ls -lah dicthtml-gt.zip
- name: upload
image: curlimages/curl
entrypoint: ["/bin/bash"]
commands:
- "curl --no-progress-meter -F '[email protected]' 'https://api.anonfile.com/upload' | grep -Eo '\"full\": *\"[^\"]+' | cut -d'\"' -f4"
- "curl --no-progress-meter -F '[email protected]' 'https://api.anonfile.com/upload' | grep -Eo '\"full\": *\"[^\"]+' | cut -d'\"' -f4"
- "curl --no-progress-meter -F '[email protected]' 'https://api.anonfile.com/upload' | grep -Eo '\"full\": *\"[^\"]+' | cut -d'\"' -f4"
- "curl --no-progress-meter -F '[email protected]' 'https://api.anonfile.com/upload' | grep -Eo '\"full\": *\"[^\"]+' | cut -d'\"' -f4"
- "echo; echo 'Don't use the dictionaries with images below right now; nickel is currently too buggy with images.'"
- "curl --no-progress-meter -F '[email protected]' 'https://api.anonfile.com/upload' | grep -Eo '\"full\": *\"[^\"]+' | cut -d'\"' -f4"
- "curl --no-progress-meter -F '[email protected]' 'https://api.anonfile.com/upload' | grep -Eo '\"full\": *\"[^\"]+' | cut -d'\"' -f4"

depends_on: [dictgen-cmd]

Expand Down
4 changes: 2 additions & 2 deletions cmd/dictgen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ func main() {
pflag.CommandLine.SortFlags = false
output := pflag.StringP("output", "o", "dicthtml.zip", "The output filename (will be overwritten if it exists) (- is stdout)")
crypt := pflag.StringP("crypt", "c", "", "Encrypt the dictzip using the specified encryption method (format: method:keyhex)")
imageMethod := pflag.StringP("image-method", "I", "base64", "How to handle images (if an image path is relative, it is loaded from the current dir) (base64 - optimize and encode as base64, embed - add to dictzip, remove)")
imageMethod := pflag.StringP("image-method", "I", "remove", "How to handle images (if an image path is relative, it is loaded from the current dir) (base64 - optimize and encode as base64, embed - add to dictzip, remove)")
help := pflag.BoolP("help", "h", false, "Show this help text")
pflag.Parse()

if *help || pflag.NArg() == 0 {
fmt.Fprintf(os.Stderr, "Usage: %s [options] dictfile...\n\nVersion: dictgen %s\n\nOptions:\n%s\nIf multiple dictfiles (*.df) are provided, they will be merged (duplicate entries are fine; they will be shown in sequential order). To read from stdin, use - as the filename.\n\nSee https://pgaskin.net/dictutil/dictgen for more information about the dictfile format.\n", os.Args[0], version, pflag.CommandLine.FlagUsages())
fmt.Fprintf(os.Stderr, "Usage: %s [options] dictfile...\n\nVersion: dictgen %s\n\nOptions:\n%s\nIf multiple dictfiles (*.df) are provided, they will be merged (duplicate entries are fine; they will be shown in sequential order). To read from stdin, use - as the filename.\n\nNote that images are currently unusable (with the exception of base64-encoded\n images in the full-screen dictionary) due to bugs in nickel. See https://github.com/geek1011/dictutil/commit/b403da2f458d50ebb45a3c52c2dd126be030c64d#commitcomment-37414958.\n\nSee https://pgaskin.net/dictutil/dictgen for more information about the dictfile format.\n", os.Args[0], version, pflag.CommandLine.FlagUsages())
os.Exit(0)
return
}
Expand Down
4 changes: 2 additions & 2 deletions dictgen/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (*ImageHandlerEmbed) Transform(src string, ir io.Reader, dw *kobodict.Write

// Description implements ImageHandler.
func (*ImageHandlerEmbed) Description() string {
return "add to dictzip as-is (warning: nickel is buggy with this as of firmware 4.19.14123)"
return "add to dictzip as-is (warning: this causes entries to appear blank due to a bug in nickel as of firmware 4.19.14123)"
}

// ImageHandlerBase64 optimizes the image and encodes it as base64. This is the
Expand Down Expand Up @@ -167,7 +167,7 @@ func (ih *ImageHandlerBase64) Transform(src string, ir io.Reader, dw *kobodict.W
// Description implements ImageHandler.
func (ih *ImageHandlerBase64) Description() string {
mw, mh, ng, jq := ih.params()
return fmt.Sprintf("optimize and encode as base64 data URL (max_width=%d, max_height=%d, grayscale=%t, jpeg_quality=%d)", mw, mh, ng, jq)
return fmt.Sprintf("optimize and encode as base64 data URL (max_width=%d, max_height=%d, grayscale=%t, jpeg_quality=%d) (warning: this causes segfaults in the in-book dictionary due to a bug in nickel as of firmware 4.19.14123)", mw, mh, ng, jq)
}

var imgTagRe = regexp.MustCompile(`(<img)(\s+(?:[^>]*\s+)?src\s*=\s*['"]+)([^'"]+)(['"][^>]*>)`)
Expand Down
4 changes: 3 additions & 1 deletion docs/dicthtml/format.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,14 @@ A dicthtml file can optionally be encrypted using AES-128-ECB encryption and PKC
### *.gif, *.jpg, etc
Dictzips can also contain a few specific types of resources. As of firmware 4.19.14123, only GIF (with the `.gif` extension and the `GIF` magic) and JPEG (with the `.jpg` extension and the `JFIF` magic) images are supported.

To reference the images, you must use a URL like `dict:///example.gif`; just `example.gif` won't work. But beware: if anything after `dict:` doesn't exist, nickel will segfault and reboot when you try to view the entry. **As of firmware 4.19.14123, including images from the dictzip using this method is slightly buggy and may cause the entire definition to appear blank. In this case, you will need to try one of the methods outlined below.**
To reference the images, you must use a URL like `dict:///example.gif`; just `example.gif` won't work. But beware: if anything after `dict:` doesn't exist, nickel will segfault and reboot when you try to view the entry.

Another way to add images is to reference them with a data URL (e.g. `<img src="data:image/gif;base64,...">`). The advantage is that you don't need to include images separately, and any filetype will work, but the disadvantage is that large images will significantly increase the loading time for the dictionary.

If you have control over the target device, you can also use `file:///...` URLs to reference a local file (which can also be of any filetype).

As of firmware 4.19.14123, all of these methods are too buggy (due to bugs in libnickel) to be usable. The only one which works is base64-encoded images in the full-screen dictionary view (i.e. not the in-book dictionary). The `dict:///` URLs cause the webview to appear blank, and the base64-encoded and file URLs cause nickel to segfault in the in-book dictionary view. See [#1](https://github.com/geek1011/dictutil/issues/1) for more details.

## Example

This is an example dictdir using most of the things mentioned above.
Expand Down

0 comments on commit 641efd5

Please sign in to comment.