public inbox for kawa@sourceware.org
 help / color / mirror / Atom feed
From: Panicz Maciej Godek <godek.maciek@gmail.com>
To: Arvydas Silanskas <nma.arvydas.silanskas@gmail.com>, kawa@sourceware.org
Subject: Re: Problem reading font data.
Date: Wed, 26 Oct 2022 22:46:30 +0200	[thread overview]
Message-ID: <CAMFYt2Y8ZMqhhUewQ6TnrLUbBD_+xUkOTZekzh_2qUaLKjD+uA@mail.gmail.com> (raw)
In-Reply-To: <CAPh7weCjXvm69=qhNv3bsDFZaGbui1G9dh5uXxOya+jzeYopOQ@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 5121 bytes --]

śr., 26 paź 2022, 22:36 użytkownik Arvydas Silanskas <
nma.arvydas.silanskas@gmail.com> napisał:

> Good day,
>
> I assume you lose the implicit classpath reference to working dir when you
> launch with java. Does it work if you add it back explicitly, ie
>
> java -cp /path/to/kawa.jar:. kawa.repl -f font-test.scm
>

Yes, this helped.
Thanks a lot!


> Not sure what are the plans for distribution, but perhaps you might want
> to load it from a file system instead of classpath.
>

Currently I have two ways of running my program: either by directly running
the .scm file, or by building a .jar file. The latter is preferable,
because it takes much less time. And the bundle also includes fonts.

I'm also building an Android client, which virtually needs to use fonts
from the bundle, because accessing the filesystem is problematic there.

Thanks again!


> Arvydas
>
>
> 2022-10-26, tr, 23:23 Panicz Maciej Godek via Kawa <kawa@sourceware.org>
> rašė:
>
>> I have the following code (it doesn't require graphics environment to
>> run):
>>
>> (define-alias Font java.awt.Font)
>> (define-alias InputStream java.io.InputStream)
>> (define ClassLoader ::java.lang.ClassLoader
>>  (java.lang.ClassLoader:getSystemClassLoader))
>>
>> (define the-graphics-environment
>>  ::parameter[java.awt.GraphicsEnvironment]
>>   (make-parameter
>>    (invoke-static
>>     java.awt.GraphicsEnvironment
>>     'getLocalGraphicsEnvironment)))
>>                                   (define (load-font path::String #!key
>> (size ::float 12.0))
>>   (let* ((font-source ::InputStream
>>     (ClassLoader:getResourceAsStream path))
>>            (font ::Font (Font:createFont
>>                        Font:TRUETYPE_FONT
>>                        font-source)))                             (invoke
>> (the-graphics-environment)
>> 'registerFont
>> font)
>>     (font:deriveFont size)))
>>
>> (define-constant Basic-Regular
>>   (load-font "assets/Basic-Regular.otf" size: 20)
>>
>> The Basic-Regular.orf file is present in the assets directory, located in
>> the same directory as the above file (that I called font-test.scm.
>>
>> When I run the code with
>>
>> $ kawa -f font-test.scm
>>
>> it behaves well. But when I instead use
>>
>> $ java -jar /path/to/kawa.jar -f font-test.scm
>>
>> or
>>
>> $ java -cp /path/to/kawa.jar kawa.repl -f font-test.scm
>>
>> I get the following error:
>>
>> java.io.IOException: Problem reading font data.                       at
>> java.desktop/java.awt.Font.createFont0(Font.java:1208)
>>                                              at
>> java.desktop/java.awt.Font.createFont(Font.java:1076)
>>                                               at
>> atInteractiveLevel$Mn8.loadFont$check(font-test.scm:21)
>>                                               at
>> gnu.mapping.CallContext.runUntilValue(CallContext.java:656)
>>                                               at
>> atInteractiveLevel$Mn9.run(font-test.scm:27)               at
>> gnu.expr.ModuleExp.evalModule2(ModuleExp.java:290)         at
>> kawa.Shell.run(Shell.java:300)                             at
>> kawa.Shell.runFile(Shell.java:562)                         at
>> kawa.Shell.runFileOrClass(Shell.java:485)                  at
>> kawa.repl.processArgs(repl.java:298)                       at
>> kawa.repl.main(repl.java:830)
>>
>> I even went so far to modify the `which kawa` script by inserting "set -x"
>> in the first line following the she-bang:
>>
>> + KAWALIB=/data/data/com.termux/files/home/usr/share/kawa/lib/kawa.jar
>>                                                 +
>>
>> CLASSPATH=/data/data/com.termux/files/home/usr/share/kawa/lib/kawa.jar:/data/data/com.termux/files/usr/share/java/android.jar:
>>                                                         + export CLASSPATH
>>                                           + test -n
>> /data/data/com.termux/files/usr/opt/openjdk         +
>> JAVA=/data/data/com.termux/files/usr/opt/openjdk/bin/java   + JVM_FLAGS=
>>                                               + exec
>> /data/data/com.termux/files/usr/opt/openjdk/bin/java
>> -Dkawa.command.line=/data/data/com.termux/files/home/usr/bin/kawa -f
>> font-test.scm -Dkawa.command.pid=20316
>> -Dkawa.home=/data/data/com.termux/files/home/usr/share/kawa kawa.repl -f
>> font-test.scm
>>
>>
>> So - in orded to minimize the differences, I typed the following
>> incantation:
>>
>> $ KAWALIB=/data/data/com.termux/files/home/usr/share/kawa/lib/kawa.jar
>> CLASSPATH=/data/data/com.termux/files/home/usr/share/kawa/lib/kawa.jar
>> /data/data/com.termux/files/usr/opt/openjdk/bin/java
>> -Dkawa.command.line="/data/data/com.termux/files/home/usr/bin/kawa -f
>> font-test.scm"
>> -Dkawa.home=/data/data/com.termux/files/home/usr/share/kawa
>> kawa.repl -f font-test.scm
>>
>> But that still doesn't work.
>> Does anyone know what could be the difference between these two runtime
>> environments?
>>
>> (I checked, and they both report the same value of (current-path))
>>
>

      parent reply	other threads:[~2022-10-26 20:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-26 20:21 Panicz Maciej Godek
     [not found] ` <CAPh7weCjXvm69=qhNv3bsDFZaGbui1G9dh5uXxOya+jzeYopOQ@mail.gmail.com>
2022-10-26 20:46   ` Panicz Maciej Godek [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAMFYt2Y8ZMqhhUewQ6TnrLUbBD_+xUkOTZekzh_2qUaLKjD+uA@mail.gmail.com \
    --to=godek.maciek@gmail.com \
    --cc=kawa@sourceware.org \
    --cc=nma.arvydas.silanskas@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).