Measure and draw shaped text with music
ASPL 0.7.0 · Current release
Measure and draw shaped text with music
On this page
Prepare the native host
Native only, published ASPL 0.7.0.
Raylib guide · API · Installation · Deployment.
Native ASPL 0.7.0 on x86_64 Linux with glibc 2.34 or later.
Running needs a reachable Wayland/EGL or X11/GLX display and OpenGL 3.3 core. Checking/building need no devices, C compiler or system Raylib.
A reachable PulseAudio/PipeWire-compatible playback service or direct ALSA device. Embedded licensed default fonts require no font download.
Keep docs/examples/assets/raylib-tone.ogg and its CC0 raylib-tone.NOTICE relative to the process working directory.
Page language and source vocabulary are independent. Keep original filenames; no translated user source is generated. Each source panel shows its checked expected behavior.
Arabic source
Execution: Native only · ASPL 0.7.0
- Native ASPL 0.7.0 on x86_64 Linux with glibc 2.34 or later.
- Running needs a reachable Wayland/EGL or X11/GLX display and OpenGL 3.3 core. Checking/building need no devices, C compiler or system Raylib.
- A reachable PulseAudio/PipeWire-compatible playback service or direct ALSA device. Embedded licensed default fonts require no font download.
- Keep the supplied OGG and its CC0 notice in the asset tree shown on this page, relative to the process working directory.
Input: No input lines are required.
Download and prepare the required files before running:
استورد أساسي::رايليب.
دالة ابدأ_الرئيسية() -> ص64 {
// لا يحتاج التخطيط والقياس شاشة. يبقى النص في ترتيبه المنطقي.
دع خط_محمل = رايليب::الخط_الافتراضي().
إذا لا خط_محمل::نجاح { اطبع(خط_محمل::الخطأ::الرسالة). أرجع 1. }
دع خيارات = رايليب::خيارات_النص {
حجم_الخط: 32.0, اتجاه: رايليب::اتجاه_نص_تلقائي,
له_عرض: صواب, عرض: 430.0, محاذاة: رايليب::محاذاة_نص_بداية,
تباعد_الأسطر: 4.0
}.
دع مجهز = رايليب::أنشئ_تخطيط_نص(خط_محمل::قيمة, "سلام ASPL 123\سبَِّ Hello", خيارات).
إذا لا مجهز::نجاح { اطبع(مجهز::الخطأ::الرسالة). أرجع 2. }
دع تخطيط = مجهز::قيمة.
دع مقاس = رايليب::قس_تخطيط_النص(تخطيط).
إذا لا مقاس::نجاح { اطبع(مقاس::الخطأ::الرسالة). أرجع 3. }
دع صوت = رايليب::هيئ_جهاز_الصوت().
إذا لا صوت::نجاح { اطبع(صوت::الخطأ::الرسالة). أرجع 4. }
دع موسيقى_محملة = رايليب::حمل_تدفق_موسيقى("docs/examples/assets/raylib-tone.ogg").
إذا لا موسيقى_محملة::نجاح { اطبع(موسيقى_محملة::الخطأ::الرسالة). أرجع 5. }
دع موسيقى = موسيقى_محملة::قيمة.
إذا لا رايليب::اضبط_تكرار_الموسيقى(موسيقى, صواب)::نجاح أو لا رايليب::شغل_تدفق_الموسيقى(موسيقى)::نجاح { أرجع 6. }
دع مفتوح = رايليب::هيئ_نافذة(500, 300, "Shaped text / نص مشكل").
إذا لا مفتوح::نجاح { اطبع(مفتوح::الخطأ::الرسالة). أرجع 7. }
إذا لا رايليب::اضبط_معدل_الإطارات(60)::نجاح { أرجع 8. }
متغير إطار: ص32 = 0.
طالما إطار < 60 {
دع إغلاق_جار = رايليب::هل_يجب_إغلاق_النافذة().
إذا لا إغلاق_جار::نجاح { أرجع 9. }
إذا إغلاق_جار::قيمة { أرجع 0. }
// يتقدم التدفق فقط عندما يستدعي التطبيق حدث_تدفق_الموسيقى.
إذا لا رايليب::حدث_تدفق_الموسيقى(موسيقى)::نجاح { أرجع 10. }
إذا لا رايليب::ابدأ_الرسم()::نجاح أو لا رايليب::امسح_الخلفية(رايليب::أبيض_رايليب)::نجاح { أرجع 11. }
دع حجم = مقاس::قيمة::حجم.
دع حبر = مقاس::قيمة::حبر.
دع صندوق = رايليب::مستطيل { س: 30.0, ص: 30.0, عرض: حجم::س, ارتفاع: حجم::ص }.
إذا لا رايليب::ارسم_محيط_مستطيل_موسعا(صندوق, 1.0, رايليب::رمادي)::نجاح { أرجع 12. }
دع صندوق_حبر = رايليب::مستطيل { س: 30.0 + حبر::س, ص: 30.0 + حبر::ص, عرض: حبر::عرض, ارتفاع: حبر::ارتفاع }.
إذا لا رايليب::ارسم_محيط_مستطيل_موسعا(صندوق_حبر, 1.0, رايليب::أحمر)::نجاح { أرجع 13. }
إذا لا رايليب::ارسم_تخطيط_النص(تخطيط, رايليب::متجه2 { س: 30.0, ص: 30.0 }, رايليب::أسود)::نجاح { أرجع 14. }
إذا لا رايليب::أنه_الرسم()::نجاح { أرجع 15. }
إطار = إطار + 1.
}
إذا لا رايليب::حرر_تدفق_الموسيقى(موسيقى)::نجاح أو لا رايليب::أغلق_جهاز_الصوت()::نجاح { أرجع 16. }
إذا لا رايليب::أغلق_النافذة()::نجاح أو لا رايليب::حرر_تخطيط_النص(تخطيط)::نجاح { أرجع 17. }
اطبع("shaped text and explicit music updates complete\س").
أرجع 0.
}
Follow the Linux instructions to run this example. Download the source to keep a copy.
Download نص-مشكل-وصوت.لباتExpected outcomes
{
"native": {
"check": 0,
"status": 0,
"behavior": {
"en": "Up to 60 frames draw logical Arabic/Latin text and marks, with gray logical-box and red ink outlines. Looping OGG advances through explicit updates. Normal completion prints shaped text and explicit music updates complete followed by a newline and returns 0. Closing early also returns 0 without that final line.",
"ar": "ترسم حتى 60 إطارا نصا عربيا ولاتينيا منطقيا وعلامات، بحدود رمادية للصندوق المنطقي وحمراء للحبر. يتقدم OGG المتكرر بتحديثات صريحة. يطبع الاكتمال الطبيعي shaped text and explicit music updates complete ثم سطرا جديدا ويعيد 0. يعيد الإغلاق المبكر أيضا 0 دون السطر النهائي."
}
}
}English source
Execution: Native only · ASPL 0.7.0
- Native ASPL 0.7.0 on x86_64 Linux with glibc 2.34 or later.
- Running needs a reachable Wayland/EGL or X11/GLX display and OpenGL 3.3 core. Checking/building need no devices, C compiler or system Raylib.
- A reachable PulseAudio/PipeWire-compatible playback service or direct ALSA device. Embedded licensed default fonts require no font download.
- Keep the supplied OGG and its CC0 notice in the asset tree shown on this page, relative to the process working directory.
Input: No input lines are required.
Download and prepare the required files before running:
import core::raylib;
fn start_main() -> i64 {
// Layout and measurement need no display. Text stays in logical order.
let loaded_font = raylib::GetFontDefault();
if not loaded_font::ok { print(loaded_font::error::message); return 1; }
let options = raylib::TextOptions {
font_size: 32.0, direction: raylib::TEXT_DIRECTION_AUTO,
has_width: true, width: 430.0, alignment: raylib::TEXT_ALIGNMENT_START,
line_spacing: 4.0
};
let prepared = raylib::CreateTextLayout(loaded_font::value, "سلام ASPL 123\nبَِّ Hello", options);
if not prepared::ok { print(prepared::error::message); return 2; }
let layout = prepared::value;
let measured = raylib::MeasureTextLayout(layout);
if not measured::ok { print(measured::error::message); return 3; }
let audio = raylib::InitAudioDevice();
if not audio::ok { print(audio::error::message); return 4; }
let loaded_music = raylib::LoadMusicStream("docs/examples/assets/raylib-tone.ogg");
if not loaded_music::ok { print(loaded_music::error::message); return 5; }
let music = loaded_music::value;
if not raylib::SetMusicLooping(music, true)::ok or not raylib::PlayMusicStream(music)::ok { return 6; }
let opened = raylib::InitWindow(500, 300, "Shaped text / نص مشكل");
if not opened::ok { print(opened::error::message); return 7; }
if not raylib::SetTargetFPS(60)::ok { return 8; }
var frame: i32 = 0;
while frame < 60 {
let closing = raylib::WindowShouldClose();
if not closing::ok { return 9; }
if closing::value { return 0; }
// Streaming advances only when the application calls UpdateMusicStream.
if not raylib::UpdateMusicStream(music)::ok { return 10; }
if not raylib::BeginDrawing()::ok or not raylib::ClearBackground(raylib::RAYWHITE)::ok { return 11; }
let size = measured::value::size;
let ink = measured::value::ink;
let box = raylib::Rectangle { x: 30.0, y: 30.0, width: size::x, height: size::y };
if not raylib::DrawRectangleLinesEx(box, 1.0, raylib::GRAY)::ok { return 12; }
let ink_box = raylib::Rectangle { x: 30.0 + ink::x, y: 30.0 + ink::y, width: ink::width, height: ink::height };
if not raylib::DrawRectangleLinesEx(ink_box, 1.0, raylib::RED)::ok { return 13; }
if not raylib::DrawTextLayout(layout, raylib::Vector2 { x: 30.0, y: 30.0 }, raylib::BLACK)::ok { return 14; }
if not raylib::EndDrawing()::ok { return 15; }
frame = frame + 1;
}
if not raylib::UnloadMusicStream(music)::ok or not raylib::CloseAudioDevice()::ok { return 16; }
if not raylib::CloseWindow()::ok or not raylib::UnloadTextLayout(layout)::ok { return 17; }
print("shaped text and explicit music updates complete\n");
return 0;
}
Follow the Linux instructions to run this example. Download the source to keep a copy.
Download shaped-text-audio.asplExpected outcomes
{
"native": {
"check": 0,
"status": 0,
"behavior": {
"en": "Up to 60 frames draw logical Arabic/Latin text and marks, with gray logical-box and red ink outlines. Looping OGG advances through explicit updates. Normal completion prints shaped text and explicit music updates complete followed by a newline and returns 0. Closing early also returns 0 without that final line.",
"ar": "ترسم حتى 60 إطارا نصا عربيا ولاتينيا منطقيا وعلامات، بحدود رمادية للصندوق المنطقي وحمراء للحبر. يتقدم OGG المتكرر بتحديثات صريحة. يطبع الاكتمال الطبيعي shaped text and explicit music updates complete ثم سطرا جديدا ويعيد 0. يعيد الإغلاق المبكر أيضا 0 دون السطر النهائي."
}
}
}Mixed source
Execution: Native only · ASPL 0.7.0
- Native ASPL 0.7.0 on x86_64 Linux with glibc 2.34 or later.
- Running needs a reachable Wayland/EGL or X11/GLX display and OpenGL 3.3 core. Checking/building need no devices, C compiler or system Raylib.
- A reachable PulseAudio/PipeWire-compatible playback service or direct ALSA device. Embedded licensed default fonts require no font download.
- Keep the supplied OGG and its CC0 notice in the asset tree shown on this page, relative to the process working directory.
Input: No input lines are required.
Download and prepare the required files before running:
import core::raylib;
استورد أساسي::رايليب.
fn start_main() -> i64 {
// Layout and measurement need no display. Text stays in logical order.
let loaded_font = raylib::GetFontDefault();
if not loaded_font::ok { print(loaded_font::error::message); return 1; }
let options = raylib::TextOptions {
font_size: 32.0, direction: raylib::TEXT_DIRECTION_AUTO,
has_width: true, width: 430.0, alignment: raylib::TEXT_ALIGNMENT_START,
line_spacing: 4.0
};
let prepared = رايليب::أنشئ_تخطيط_نص(loaded_font::value, "سلام ASPL 123\nبَِّ Hello", options);
if not prepared::ok { print(prepared::error::message); return 2; }
let layout = prepared::value;
let measured = raylib::MeasureTextLayout(layout);
if not measured::ok { print(measured::error::message); return 3; }
let audio = رايليب::هيئ_جهاز_الصوت();
if not audio::ok { print(audio::error::message); return 4; }
let loaded_music = raylib::LoadMusicStream("docs/examples/assets/raylib-tone.ogg");
if not loaded_music::ok { print(loaded_music::error::message); return 5; }
let music = loaded_music::value;
if not raylib::SetMusicLooping(music, true)::ok or not raylib::PlayMusicStream(music)::ok { return 6; }
let opened = raylib::InitWindow(500, 300, "Shaped text / نص مشكل");
if not opened::ok { print(opened::error::message); return 7; }
if not raylib::SetTargetFPS(60)::ok { return 8; }
var frame: i32 = 0;
while frame < 60 {
let closing = raylib::WindowShouldClose();
if not closing::ok { return 9; }
if closing::value { return 0; }
// Streaming advances only when the application calls UpdateMusicStream.
if not raylib::UpdateMusicStream(music)::ok { return 10; }
if not raylib::BeginDrawing()::ok or not raylib::ClearBackground(raylib::RAYWHITE)::ok { return 11; }
let size = measured::value::size;
let ink = measured::value::ink;
let box = raylib::Rectangle { x: 30.0, y: 30.0, width: size::x, height: size::y };
if not raylib::DrawRectangleLinesEx(box, 1.0, raylib::GRAY)::ok { return 12; }
let ink_box = raylib::Rectangle { x: 30.0 + ink::x, y: 30.0 + ink::y, width: ink::width, height: ink::height };
if not raylib::DrawRectangleLinesEx(ink_box, 1.0, raylib::RED)::ok { return 13; }
if not رايليب::ارسم_تخطيط_النص(layout, raylib::Vector2 { x: 30.0, y: 30.0 }, raylib::BLACK)::ok { return 14; }
if not raylib::EndDrawing()::ok { return 15; }
frame = frame + 1;
}
if not raylib::UnloadMusicStream(music)::ok or not raylib::CloseAudioDevice()::ok { return 16; }
if not raylib::CloseWindow()::ok or not raylib::UnloadTextLayout(layout)::ok { return 17; }
print("shaped text and explicit music updates complete\n");
return 0;
}
Follow the Linux instructions to run this example. Download the source to keep a copy.
Download shaped-text-audio.mixed.asplExpected outcomes
{
"native": {
"check": 0,
"status": 0,
"behavior": {
"en": "Up to 60 frames draw logical Arabic/Latin text and marks, with gray logical-box and red ink outlines. Looping OGG advances through explicit updates. Normal completion prints shaped text and explicit music updates complete followed by a newline and returns 0. Closing early also returns 0 without that final line.",
"ar": "ترسم حتى 60 إطارا نصا عربيا ولاتينيا منطقيا وعلامات، بحدود رمادية للصندوق المنطقي وحمراء للحبر. يتقدم OGG المتكرر بتحديثات صريحة. يطبع الاكتمال الطبيعي shaped text and explicit music updates complete ثم سطرا جديدا ويعيد 0. يعيد الإغلاق المبكر أيضا 0 دون السطر النهائي."
}
}
}Commands and outcomes
Check/build acquire no device. Run from the directory containing the prepared docs/ tree. Keep the generated .THIRD-PARTY-NOTICES companion when distributing the ELF.
ar:
aspl check docs/examples/raylib/نص-مشكل-وصوت.لبات
aspl run docs/examples/raylib/نص-مشكل-وصوت.لبات
aspl build -o raylib-shaped-text-audio-ar-program docs/examples/raylib/نص-مشكل-وصوت.لبات
./raylib-shaped-text-audio-ar-programen:
aspl check docs/examples/raylib/shaped-text-audio.aspl
aspl run docs/examples/raylib/shaped-text-audio.aspl
aspl build -o raylib-shaped-text-audio-en-program docs/examples/raylib/shaped-text-audio.aspl
./raylib-shaped-text-audio-en-programmixed:
aspl check docs/examples/raylib/shaped-text-audio.mixed.aspl
aspl run docs/examples/raylib/shaped-text-audio.mixed.aspl
aspl build -o raylib-shaped-text-audio-mixed-program docs/examples/raylib/shaped-text-audio.mixed.aspl
./raylib-shaped-text-audio-mixed-programFailed audio initialization prints its bilingual message and returns 4. If audio succeeds but the display is absent, the window failure prints and status is 7. A missing OGG prints the load failure and returns 5. Closing early returns 0 through automatic cleanup.