Skip to content

Commit

Permalink
For text Pictures, enable specifying of font during creation.
Browse files Browse the repository at this point in the history
  • Loading branch information
litan committed May 6, 2022
1 parent 2ee0559 commit 32f8d31
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
5 changes: 3 additions & 2 deletions src/main/scala/net/kogics/kojo/lite/Builtins.scala
Original file line number Diff line number Diff line change
Expand Up @@ -615,8 +615,9 @@ Here's a partial list of the available commands:
val PicShape = Picture
implicit def p2rp(path: GeneralPath): Rich2DPath = new Rich2DPath(path)
object Picture {
def text(content: Any, fontSize: Int = 15) = picture.textu(content, fontSize, red)
def textu(content: Any, fontSize: Int = 15, color: Color = red) = picture.textu(content, fontSize, color)
def text(content: Any, fontSize: Int = 15) = picture.text(content, fontSize, red)
def text(content: Any, font: Font) = picture.text(content, font, red)
def textu(content: Any, fontSize: Int = 15, color: Color = red) = picture.text(content, fontSize, color)
def rect(h: Double, w: Double) = picture.rect2(w, h)
def rectangle(width: Double, height: Double) = picture.rect2(width, height)
// def rectangle(x: Double, y: Double, w: Double, h: Double) = picture.offset(x, y) -> picture.rect2(w, h)
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/net/kogics/kojo/lite/Versions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package net.kogics.kojo.lite
object Versions {
val KojoMajorVersion = "2.9"
val KojoVersion = "2.9.21"
val KojoRevision = "r4"
val KojoRevision = "r5"
val KojoBuildDate = "6 May 2022"
val JavaVersion = {
val jrv = System.getProperty("java.runtime.version")
Expand Down
15 changes: 7 additions & 8 deletions src/main/scala/net/kogics/kojo/picture/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,19 @@
*/
package net.kogics.kojo

import java.awt.Color
import java.awt.Image
import java.awt.Paint
import java.awt.{Color, Font, Image, Paint}
import java.awt.event.KeyEvent
import java.awt.geom.GeneralPath
import java.awt.image.BufferedImageOp
import java.net.URL
import java.util.Random

import javax.swing.JComponent

import scala.swing.Graphics2D

import com.jhlabs.image.LightFilter
import com.jhlabs.image.LightFilter.Light
import com.vividsolutions.jts.geom.Coordinate
import com.vividsolutions.jts.geom.GeometryFactory
import com.vividsolutions.jts.geom.PrecisionModel

import net.kogics.kojo.core.Cm
import net.kogics.kojo.core.Inch
import net.kogics.kojo.core.Pixel
Expand Down Expand Up @@ -149,7 +143,12 @@ package object picture {
write(s)
}

def textu(s0: Any, fontSize: Int, color: Color)(implicit canvas: SCanvas) = new TextPic(s0.toString, fontSize, color)
def text(s0: Any, fontSize: Int, color: Color)(implicit canvas: SCanvas): TextPic = new TextPic(s0.toString, fontSize, color)
def text(s0: Any, font: Font, color: Color)(implicit canvas: SCanvas): TextPic = {
val ret = text(s0, 15, color)
ret.setPenFont(font)
ret
}

def rect(h: Double, w: Double)(implicit canvas: SCanvas) = Pic { t =>
Utils.trect(h, w, t)
Expand Down
4 changes: 3 additions & 1 deletion src/main/scala/net/kogics/kojo/xscala/Help.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1236,12 +1236,14 @@ The code that you provide to react runs about thirty times per second, in the UI
"Picture.text" ->
<div>
<strong>Picture.text</strong>(content, size) - Creates a picture out of the given text with the given font-size.<br/>
<strong>Picture.text</strong>(content, font) - Creates a picture out of the given text with the given font.<br/>
<br/>
<em>Example:</em> <br/>
<br/>
<pre>
cleari()
draw(Picture.text("Hi There", 18))
//draw(Picture.text("Hi There", 30))
draw(Picture.text("Hi There", Font("Serif", 30)))
</pre>
</div>,
"Picture.image" ->
Expand Down

0 comments on commit 32f8d31

Please sign in to comment.