Skip to content

Translation: visualize image #81

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

Merged
merged 4 commits into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 30 additions & 34 deletions crates/typst/src/visualize/image/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,12 @@ use crate::utils::LazyHash;
use crate::visualize::Path;
use crate::World;

/// A raster or vector graphic.
/// ラスターまたはベクター画像。
///
/// You can wrap the image in a [`figure`] to give it a number and caption.
/// 画像を[`figure`]で囲むことで、番号とキャプションを与えることができます。
///
/// Like most elements, images are _block-level_ by default and thus do not
/// integrate themselves into adjacent paragraphs. To force an image to become
/// inline, put it into a [`box`].
/// ほとんどの要素と同様に、画像はデフォルトでは _ブロックレベル_ であるため、隣接する段落に統合されることはありません。
/// 画像を強制的にインラインにするには、[`box`]の中に入れてください。
///
/// # Example
/// ```example
Expand All @@ -52,9 +51,9 @@ use crate::World;
/// ```
#[elem(scope, Show, LocalName, Figurable)]
pub struct ImageElem {
/// Path to an image file
/// 画像ファイルのパス。
///
/// For more details, see the [Paths section]($syntax/#paths).
/// より詳細な情報は[パスの章]($syntax/#paths)を参照してください。
#[required]
#[parse(
let Spanned { v: path, span } =
Expand All @@ -72,25 +71,24 @@ pub struct ImageElem {
#[parse(Readable::Bytes(data))]
pub data: Readable,

/// The image's format. Detected automatically by default.
/// 画像のフォーマット。デフォルトでは自動的に検出されます。
///
/// Supported formats are PNG, JPEG, GIF, and SVG. Using a PDF as an image
/// is [not currently supported](https://github.com/typst/typst/issues/145).
/// サポートされている拡張子は PNG, JPEG, GIF, SVGです。
/// [PDFの画像はまだサポートされていません。](https://github.com/typst/typst/issues/145)
pub format: Smart<ImageFormat>,

/// The width of the image.
/// 画像の幅。
pub width: Smart<Rel<Length>>,

/// The height of the image.
/// 画像の高さ。
pub height: Sizing,

/// A text describing the image.
/// 画像の説明文。
pub alt: Option<EcoString>,

/// How the image should adjust itself to a given area (the area is defined
/// by the `width` and `height` fields). Note that `fit` doesn't visually
/// change anything if the area's aspect ratio is the same as the image's
/// one.
/// 与えられた領域に対して、画像をどのように調整するか。
/// 領域は `width` や `height` フィールドで定義します。
/// 領域の縦横比が画像の縦横比と同じであれば、`fit` で見た目が変わらないことに注意してください。
///
/// ```example
/// #set page(width: 300pt, height: 50pt, margin: 10pt)
Expand All @@ -104,7 +102,7 @@ pub struct ImageElem {

#[scope]
impl ImageElem {
/// Decode a raster or vector graphic from bytes or a string.
/// バイトまたは文字列からラスターまたはベクトル図形をデコードします。
///
/// ```example
/// #let original = read("diagram.svg")
Expand All @@ -120,21 +118,21 @@ impl ImageElem {
pub fn decode(
/// The call span of this function.
span: Span,
/// The data to decode as an image. Can be a string for SVGs.
/// 画像としてデコードするデータ。SVG の場合は文字列です。
data: Readable,
/// The image's format. Detected automatically by default.
/// 画像のフォーマット。デフォルトでは自動的に検出されます。
#[named]
format: Option<Smart<ImageFormat>>,
/// The width of the image.
/// 画像の幅。
#[named]
width: Option<Smart<Rel<Length>>>,
/// The height of the image.
/// 画像の高さ。
#[named]
height: Option<Sizing>,
/// A text describing the image.
/// 画像の説明文。
#[named]
alt: Option<Option<EcoString>>,
/// How the image should adjust itself to a given area.
/// 与えられた領域に対して、画像をどのように調整するか。
#[named]
fit: Option<ImageFit>,
) -> StrResult<Content> {
Expand Down Expand Up @@ -305,17 +303,15 @@ fn determine_format(path: &str, data: &Readable) -> StrResult<ImageFormat> {
/// How an image should adjust itself to a given area,
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Cast)]
pub enum ImageFit {
/// The image should completely cover the area (preserves aspect ratio by
/// cropping the image only horizontally or vertically). This is the
/// default.
/// 領域を完全にカバーします。
/// 水平または垂直方向にのみ画像をトリミングすることで、アスペクト比を保持します。
/// これがデフォルトです。
Cover,
/// The image should be fully contained in the area (preserves aspect
/// ratio; doesn't crop the image; one dimension can be narrower than
/// specified).
/// 画像は領域内に完全に収まるようにします。
/// アスペクト比を維持して、画像を切り取らず、1つの寸法は指定より狭くします。
Contain,
/// The image should be stretched so that it exactly fills the area, even if
/// this means that the image will be distorted (doesn't preserve aspect
/// ratio and doesn't crop the image).
/// たとえ画像が歪むことになっても、その領域を正確に埋めるように引き伸ばします。
/// アスペクト比は保たれず、画像は切り取られません。
Stretch,
}

Expand Down Expand Up @@ -467,7 +463,7 @@ pub enum ImageFormat {
/// A vector graphics format.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Cast)]
pub enum VectorFormat {
/// The vector graphics format of the web.
/// Webサイトに用いられるベクターフォーマット。
Svg,
}

Expand Down
6 changes: 3 additions & 3 deletions crates/typst/src/visualize/image/raster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ impl Hash for Repr {
/// A raster graphics format.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Cast)]
pub enum RasterFormat {
/// Raster format for illustrations and transparent graphics.
/// イラストや透明グラフィック用のラスターフォーマット。
Png,
/// Lossy raster format suitable for photos.
/// 写真に適した非可逆ラスターフォーマット。
Jpg,
/// Raster format that is typically used for short animated clips.
/// 短いアニメーションクリップによく使われるラスターフォーマット。
Gif,
}

Expand Down
2 changes: 1 addition & 1 deletion docs/reference/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ I got an ice cream for
\$1.50! \u{1f600}
```

## Paths
## パス { #paths }
Typst has various features that require a file path to reference external
resources such as images, Typst files, or data files. Paths are represented as
[strings]($str). There are two kinds of paths: Relative and absolute.
Expand Down