Files
openchamber-android-native/third_party/mygo/internal/text/stub.go
T
OpenChamber 6c0ee61750 feat: port the client to MyGo native UI (0.3.0)
Switch from Asuka to MyGo, keeping the API client and the feature set:

- servers: saved servers, passwordless and password login, proxy,
  self-signed certificates, per-server device tokens (Keystore), connect
  form, instance list sheet with switch/disconnect
- sessions: virtualized list, search, new session, rename/archive/delete,
  running indicator, event stream keeps it live
- chat: pushed window with system back bar, streaming Markdown via
  ui/markdown, reasoning and tool rows with image previews, footer menu
  (read aloud via a Kotlin TTS plugin, copy, fork), user message menu
  (copy, revert, fork), context usage ring and detail sheet, attachments
  (photos/files via the document picker), permissions
- release builds allow plain http:// LAN servers (Go's net/http dials
  directly, no cleartext manifest needed)
- a local fork of MyGo (third_party/mygo) lowers the Android host's
  minSdk to 24 (Android 7.0); Go 1.27.4 via mise

Version 0.3.0.
2026-11-18 13:22:59 +08:00

60 lines
1.7 KiB
Go

package text
import (
"errors"
"math"
"github.com/egoist/mygo/internal/scene"
)
// stubEngine lays out text without fonts where the system has no text
// engine MyGo can use: every rune takes half an em and draws nothing.
type stubEngine struct {
shapeScratch
fonts map[float32]*Font
}
func (e *stubEngine) font(style Style) *Font {
size := style.FontSize()
if f, ok := e.fonts[size]; ok {
return f
}
if e.fonts == nil {
e.fonts = map[float32]*Font{}
}
f := &Font{Size: size, Ascent: size * 0.8, Descent: size * 0.2}
e.fonts[size] = f
return f
}
func (e *stubEngine) shape(text []rune, style Style, spans []Span, width float32, rtl, wholeWords bool) []shapedLine {
f := e.font(style)
run := shapedRun{font: f, end: len(text)}
for i := range text {
run.glyphs = append(run.glyphs, Glyph{Font: f, X: float32(i) * f.Size / 2, Advance: f.Size / 2, Cluster: i, RTL: rtl})
}
return []shapedLine{{end: len(text), runs: []shapedRun{run}}}
}
func (e *stubEngine) glyph(f *Font, id uint32, scale, dx float32, _ Shade, _ bool) bitmap {
return bitmap{}
}
func (e *stubEngine) textParams() (scene.TextParams, bool) { return scene.TextParams{}, false }
func (e *stubEngine) positions(*Font, float32, bool) (int, bool) { return 1, true }
func (e *stubEngine) decorate(decoRange) []Stroke { return nil }
func (e *stubEngine) join() bool { return false }
func (e *stubEngine) baseline(y float32) float32 { return float32(math.Round(float64(y))) }
func (e *stubEngine) appFamilies() []FontFamily { return nil }
func (e *stubEngine) systemFamilies() func() []FontFamily { return nil }
func (e *stubEngine) register(data []byte, family string) error {
return errors.New("mygo: this system has no text engine to add fonts to")
}