Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add primitive use-image to use image by natural size #297

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

yasuo-ozu
Copy link
Contributor

Add the primitives:

use-image-by-natural-size : image -> inline-cmd

This is implementation of #296

@na4zagin3
Copy link
Contributor

Just my two cents. Why not add a primitive that gets the soze (e.g., get-image-size : image -> (length * length)) instead?

@gfngfn
Copy link
Owner

gfngfn commented Oct 27, 2021

Thank you for the development!

It also looks more preferable to me to provide get-image-size as na4zagin3-san suggests than to add use-image-by-natural-size. This is because use-image-by-natural-size can be easily implemented by using get-image-size (and use-image-by-width) but the opposite seems more complex; get-image-size would be thereby a more “primitive” operation.

@yasuo-ozu
Copy link
Contributor Author

yasuo-ozu commented Oct 28, 2021

Thanks for replaying.

From my standings, I want to replace use-image-by-width with use-image-by-natural-size (= use-image), because use-image-by-width too respects image width (than height) so I think it is irrational. So use-image seems more primitive than use-image-by-width.

Using use-image and existing commands, the following commands can defined:

let get-image-size img =
    let ib = use-image img in
    let (w, h, d) = get-natural-metrics ib in
    (w, h)
let use-image-by-width img wid =
    let ib = use-image img in
    let (w, h, d) = get-natural-metrics ib in
    let hgt = h *' (wid /' w) in
    inline-graphics wid hgt 0pt (fun (x, y) -> (
        let g = draw-text (x, y) ib in
        linear-transform-graphics g
    ))

@yasuo-ozu
Copy link
Contributor Author

yasuo-ozu commented Oct 28, 2021

To be short:
既存のuse-image-by-widthwidthを特別扱いしているのであまり合理的でなく、今のSATySFiではlinear-transform-graphicsが使えるのだから、use-imageをprimitiveにしてuse-image-by-widthはライブラリ定義にしたほうが良いのでは?という意見です。

違う例としては

get-initial-context : length -> [math] inline-cmd -> context

があるわけですが、これにおけるlengthは画像におけるlengthとは意味が異なる(文書のcolumnの幅)ので違和感はないです。

(ただこれはあくまで1意見であり、get-image-sizeの方が良さそうであればuse-image-by-natural-sizeを消してget-image-sizeを追加しようとおもいます)

@yasuo-ozu yasuo-ozu changed the title Add primitive BackendUseImageByNaturalSize Add primitive use-image to use image by natural size Mar 16, 2022
@yasuo-ozu
Copy link
Contributor Author

I updated the implementation to come up with the following ideas:

  • Add primitive use-image (called use-image-by-natural-size in upstream discussion) to import image by its natural size.
  • Delete use-image-by-width from vminst.ml and re-implemented it in pervasives.satyh, which is no longer primitive, just a library definition.

Key point is:
I think, use-image is more primitive than use-image-by-width

Is there any comments on this idea?
Thanks a lot.

@yasuo-ozu
Copy link
Contributor Author

以下のアイデアを実現するために実装を更新しました。

  • 画像を「自然なサイズ」で使用するuse-imageプリミティブ(上のdiscussionでuse-image-by-widthと呼んでいたもの)を実装した。
  • use-image-by-widthvminst.mlから削除し、ライブラリ定義としてpervasives.satyhに再実装した。

キーポイントは
私は思う, use-imageuse-image-by-widthよりもprimitiveであると。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In progress (v0.0.x)
Development

Successfully merging this pull request may close these issues.

3 participants