2023-06-24 18:56:47 +02:00
|
|
|
// Copyright 2023 The Ebitengine Authors
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2023-07-01 12:57:42 +02:00
|
|
|
// This example is a demonstration to render languages that cannot be rendered with the `text` package.
|
|
|
|
// We plan to provide a useful API to render them more easily (#2454). Stay tuned!
|
|
|
|
|
2023-06-24 18:56:47 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
_ "embed"
|
|
|
|
"log"
|
|
|
|
|
2023-11-12 09:47:31 +01:00
|
|
|
"golang.org/x/text/language"
|
2023-06-24 18:56:47 +02:00
|
|
|
|
|
|
|
"github.com/hajimehoshi/ebiten/v2"
|
|
|
|
"github.com/hajimehoshi/ebiten/v2/examples/resources/fonts"
|
2023-11-12 09:47:31 +01:00
|
|
|
"github.com/hajimehoshi/ebiten/v2/text/v2"
|
2023-06-24 18:56:47 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
//go:embed NotoSansArabic-Regular.ttf
|
|
|
|
var arabicTTF []byte
|
|
|
|
|
2023-11-12 09:47:31 +01:00
|
|
|
var arabicFaceSource *text.GoTextFaceSource
|
2023-06-24 18:56:47 +02:00
|
|
|
|
|
|
|
func init() {
|
2023-11-12 09:47:31 +01:00
|
|
|
s, err := text.NewGoTextFaceSource(bytes.NewReader(arabicTTF))
|
2023-06-24 18:56:47 +02:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2023-11-12 09:47:31 +01:00
|
|
|
arabicFaceSource = s
|
2023-06-24 18:56:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//go:embed NotoSansDevanagari-Regular.ttf
|
|
|
|
var devanagariTTF []byte
|
|
|
|
|
2023-11-12 09:47:31 +01:00
|
|
|
var devanagariFaceSource *text.GoTextFaceSource
|
2023-06-24 18:56:47 +02:00
|
|
|
|
|
|
|
func init() {
|
2023-11-12 09:47:31 +01:00
|
|
|
s, err := text.NewGoTextFaceSource(bytes.NewReader(devanagariTTF))
|
2023-06-24 18:56:47 +02:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2023-11-12 09:47:31 +01:00
|
|
|
devanagariFaceSource = s
|
2023-06-24 18:56:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//go:embed NotoSansThai-Regular.ttf
|
|
|
|
var thaiTTF []byte
|
|
|
|
|
2023-11-12 09:47:31 +01:00
|
|
|
var thaiFaceSource *text.GoTextFaceSource
|
2023-06-24 18:56:47 +02:00
|
|
|
|
|
|
|
func init() {
|
2023-11-12 09:47:31 +01:00
|
|
|
s, err := text.NewGoTextFaceSource(bytes.NewReader(thaiTTF))
|
2023-06-24 18:56:47 +02:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2023-11-12 09:47:31 +01:00
|
|
|
thaiFaceSource = s
|
2023-06-24 18:56:47 +02:00
|
|
|
}
|
|
|
|
|
2023-11-12 09:47:31 +01:00
|
|
|
var japaneseFaceSource *text.GoTextFaceSource
|
2023-06-24 18:56:47 +02:00
|
|
|
|
|
|
|
func init() {
|
2023-11-12 09:47:31 +01:00
|
|
|
s, err := text.NewGoTextFaceSource(bytes.NewReader(fonts.MPlus1pRegular_ttf))
|
2023-06-24 18:56:47 +02:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2023-11-12 09:47:31 +01:00
|
|
|
japaneseFaceSource = s
|
2023-06-24 18:56:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const (
|
|
|
|
screenWidth = 640
|
|
|
|
screenHeight = 480
|
|
|
|
)
|
|
|
|
|
|
|
|
type Game struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *Game) Update() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *Game) Draw(screen *ebiten.Image) {
|
2023-11-12 09:47:31 +01:00
|
|
|
const arabicText = "لمّا كان الاعتراف بالكرامة المتأصلة في جميع"
|
|
|
|
|
|
|
|
op := &text.DrawOptions{}
|
2023-11-15 04:35:34 +01:00
|
|
|
op.GeoM.Translate(screenWidth-20, 40)
|
2023-11-12 09:47:31 +01:00
|
|
|
text.Draw(screen, arabicText, &text.GoTextFace{
|
2023-11-15 13:52:25 +01:00
|
|
|
Source: arabicFaceSource,
|
|
|
|
Direction: text.DirectionRightToLeft,
|
|
|
|
Size: 24,
|
|
|
|
Language: language.Arabic,
|
2023-11-12 09:47:31 +01:00
|
|
|
}, op)
|
|
|
|
|
|
|
|
const hindiText = "चूंकि मानव परिवार के सभी सदस्यों के जन्मजात गौरव और समान"
|
|
|
|
|
|
|
|
op.GeoM.Reset()
|
2023-11-15 04:35:34 +01:00
|
|
|
op.GeoM.Translate(20, 110)
|
2023-11-12 09:47:31 +01:00
|
|
|
text.Draw(screen, hindiText, &text.GoTextFace{
|
2023-11-15 13:52:25 +01:00
|
|
|
Source: devanagariFaceSource,
|
|
|
|
Size: 24,
|
|
|
|
Language: language.Hindi,
|
2023-11-12 09:47:31 +01:00
|
|
|
}, op)
|
|
|
|
|
|
|
|
const thaiText = "โดยที่การไม่นำพาและการหมิ่นในคุณค่าของสิทธิมนุษยชน"
|
|
|
|
|
|
|
|
op.GeoM.Reset()
|
2023-11-15 04:35:34 +01:00
|
|
|
op.GeoM.Translate(20, 160)
|
2023-11-12 09:47:31 +01:00
|
|
|
text.Draw(screen, thaiText, &text.GoTextFace{
|
2023-11-15 13:52:25 +01:00
|
|
|
Source: thaiFaceSource,
|
|
|
|
Size: 24,
|
|
|
|
Language: language.Thai,
|
2023-11-12 09:47:31 +01:00
|
|
|
}, op)
|
|
|
|
|
2023-11-15 04:35:34 +01:00
|
|
|
const japaneseText = "あのイーハトーヴォの\nすきとおった風、\n夏でも底に冷たさを\nもつ青いそら…"
|
2023-11-12 09:47:31 +01:00
|
|
|
|
|
|
|
op.GeoM.Reset()
|
2023-11-15 04:35:34 +01:00
|
|
|
op.GeoM.Translate(screenWidth-20, 210)
|
2023-11-16 17:17:29 +01:00
|
|
|
op.LineSpacingInPixels = 48
|
2023-11-12 09:47:31 +01:00
|
|
|
text.Draw(screen, japaneseText, &text.GoTextFace{
|
2023-11-15 13:52:25 +01:00
|
|
|
Source: japaneseFaceSource,
|
|
|
|
Direction: text.DirectionTopToBottomAndRightToLeft,
|
|
|
|
Size: 24,
|
|
|
|
Language: language.Japanese,
|
2023-11-12 09:47:31 +01:00
|
|
|
}, op)
|
2023-06-24 18:56:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
|
|
|
|
return screenWidth, screenHeight
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
ebiten.SetWindowSize(screenWidth, screenHeight)
|
|
|
|
ebiten.SetWindowTitle("Text I18N (Ebitengine Demo)")
|
|
|
|
if err := ebiten.RunGame(&Game{}); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|