Skip to content

Commit

Permalink
[orx-panel] Load fonts through loadFont instead FontImageMap.fromUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
edwinRNDR committed Sep 27, 2024
1 parent 98851e0 commit 7c2e55b
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ class ControlManager : Extension {

val mouseInput = MouseInput()
override fun setup(program: Program) {

fontManager.program = program
this.program = program

contentScale = program.window.contentScale
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package org.openrndr.panel

import org.openrndr.Program
import org.openrndr.draw.FontImageMap
import org.openrndr.draw.loadFont
import org.openrndr.panel.style.LinearDimension
import org.openrndr.panel.style.StyleSheet
import org.openrndr.panel.style.fontFamily
import org.openrndr.panel.style.fontSize

class FontManager {
class FontManager() {
var program: Program? = null
val registry: MutableMap<String, String> = mutableMapOf()
var contentScale: Double = 1.0

Expand All @@ -15,7 +18,7 @@ class FontManager {
fun font(cs: StyleSheet): FontImageMap {
val fontUrl = resolve(cs.fontFamily) ?: "cp:fonts/Roboto-Medium.ttf"
val fontSize = (cs.fontSize as? LinearDimension.PX)?.value ?: 16.0
return FontImageMap.fromUrl(fontUrl, fontSize, contentScale = contentScale)
return program?.loadFont(fontUrl, fontSize) ?: error("no program")
}

fun register(name: String, url: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package org.openrndr.panel.elements

import org.openrndr.color.ColorRGBa
import org.openrndr.draw.Drawer
import org.openrndr.draw.FontImageMap

import org.openrndr.draw.isolated
import org.openrndr.draw.loadFont
import org.openrndr.events.Event
import org.openrndr.extra.textwriter.TextWriter
import org.openrndr.panel.style.*
Expand Down Expand Up @@ -52,7 +52,9 @@ class Button : Element(ElementType("button")) {
computedStyle.let { style ->
val fontUrl = (root() as? Body)?.controlManager?.fontManager?.resolve(style.fontFamily) ?: "broken"
val fontSize = (style.fontSize as? LinearDimension.PX)?.value ?: 14.0
val fontMap = FontImageMap.fromUrl(fontUrl, fontSize)

val program = (root() as? Body)?.controlManager?.program ?: error("no program")
val fontMap = program.loadFont(fontUrl, fontSize)

val writer = TextWriter(null)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import kotlinx.coroutines.yield
import org.openrndr.KEY_ARROW_DOWN
import org.openrndr.KEY_ARROW_UP
import org.openrndr.KEY_ENTER
import org.openrndr.draw.loadFont

import org.openrndr.events.Event
import org.openrndr.launch
Expand Down Expand Up @@ -79,7 +80,10 @@ class DropdownButton : Element(ElementType("dropdown-button")), DisposableElemen
computedStyle.let { style ->
val fontUrl = (root() as? Body)?.controlManager?.fontManager?.resolve(style.fontFamily) ?: "broken"
val fontSize = (style.fontSize as? LinearDimension.PX)?.value ?: 16.0
val fontMap = FontImageMap.fromUrl(fontUrl, fontSize)

val program = (root() as? Body)?.controlManager?.program ?: error("no program")
val fontMap = program.loadFont(fontUrl, fontSize)

val writer = TextWriter(null)

writer.box = Rectangle(0.0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import kotlinx.coroutines.yield
import org.openrndr.color.ColorRGBa
import org.openrndr.draw.Drawer
import org.openrndr.draw.FontImageMap
import org.openrndr.draw.loadFont
import org.openrndr.extra.textwriter.TextWriter

import org.openrndr.launch
Expand Down Expand Up @@ -34,7 +35,8 @@ class TextNode(var text: String) : Element(ElementType("text")) {
computedStyle.let { style ->
val fontUrl = (root() as? Body)?.controlManager?.fontManager?.resolve(style.fontFamily)?:"broken"
val fontSize = (style.fontSize as? LinearDimension.PX)?.value?: 14.0
val fontMap = FontImageMap.fromUrl(fontUrl, fontSize)
val program = (root() as? Body)?.controlManager?.program ?: error("no program")
val fontMap = program.loadFont(fontUrl, fontSize)

val writer = TextWriter(null)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import kotlinx.coroutines.*
import org.openrndr.draw.Drawer
import org.openrndr.draw.FontImageMap
import org.openrndr.draw.LineCap
import org.openrndr.draw.loadFont
import org.openrndr.panel.style.*
import org.openrndr.shape.Rectangle

Expand Down Expand Up @@ -34,7 +35,8 @@ class Toggle : Element(ElementType("toggle")), DisposableElement {
computedStyle.let { style ->
val fontUrl = (root() as? Body)?.controlManager?.fontManager?.resolve(style.fontFamily) ?: "broken"
val fontSize = (style.fontSize as? LinearDimension.PX)?.value ?: 14.0
val fontMap = FontImageMap.fromUrl(fontUrl, fontSize)
val program = (root() as? Body)?.controlManager?.program ?: error("no program")
val fontMap = program.loadFont(fontUrl, fontSize)

val writer = TextWriter(null)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.openrndr.color.ColorRGBa
import org.openrndr.draw.Drawer
import org.openrndr.draw.FontImageMap
import org.openrndr.draw.isolated
import org.openrndr.draw.loadFont
import org.openrndr.extra.textwriter.writer

import org.openrndr.math.Vector2
Expand All @@ -16,7 +17,9 @@ class Tooltip(val parent: Element, val position: Vector2, val message: String) {

val fontUrl = (parent.root() as Body).controlManager.fontManager.resolve("default") ?: error("no font")
val fontSize = 14.0
val fontMap = FontImageMap.fromUrl(fontUrl, fontSize)
val program = (parent.root() as? Body)?.controlManager?.program ?: error("no program")
val fontMap = program.loadFont(fontUrl, fontSize)

val lines = message.split("\n")

drawer.isolated {
Expand Down

0 comments on commit 7c2e55b

Please sign in to comment.