libquinn now uses freetype!

This commit is contained in:
Andrew Pamment 2016-01-19 15:55:27 +10:00
parent ba70082358
commit 43bf35b75c
30 changed files with 199 additions and 59 deletions

BIN
fonts/DejaVuSans-Bold.ttf Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
fonts/DejaVuSans.ttf Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
fonts/DejaVuSansMono.ttf Normal file

Binary file not shown.

BIN
fonts/DejaVuSerif-Bold.ttf Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
fonts/DejaVuSerif.ttf Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

99
fonts/LICENSE Normal file
View File

@ -0,0 +1,99 @@
Fonts are (c) Bitstream (see below). DejaVu changes are in public domain.
Glyphs imported from Arev fonts are (c) Tavmjong Bah (see below)
Bitstream Vera Fonts Copyright
------------------------------
Copyright (c) 2003 by Bitstream, Inc. All Rights Reserved. Bitstream Vera is
a trademark of Bitstream, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of the fonts accompanying this license ("Fonts") and associated
documentation files (the "Font Software"), to reproduce and distribute the
Font Software, including without limitation the rights to use, copy, merge,
publish, distribute, and/or sell copies of the Font Software, and to permit
persons to whom the Font Software is furnished to do so, subject to the
following conditions:
The above copyright and trademark notices and this permission notice shall
be included in all copies of one or more of the Font Software typefaces.
The Font Software may be modified, altered, or added to, and in particular
the designs of glyphs or characters in the Fonts may be modified and
additional glyphs or characters may be added to the Fonts, only if the fonts
are renamed to names not containing either the words "Bitstream" or the word
"Vera".
This License becomes null and void to the extent applicable to Fonts or Font
Software that has been modified and is distributed under the "Bitstream
Vera" names.
The Font Software may be sold as part of a larger software package but no
copy of one or more of the Font Software typefaces may be sold by itself.
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT,
TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL BITSTREAM OR THE GNOME
FOUNDATION BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING
ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE
FONT SOFTWARE.
Except as contained in this notice, the names of Gnome, the Gnome
Foundation, and Bitstream Inc., shall not be used in advertising or
otherwise to promote the sale, use or other dealings in this Font Software
without prior written authorization from the Gnome Foundation or Bitstream
Inc., respectively. For further information, contact: fonts at gnome dot
org.
Arev Fonts Copyright
------------------------------
Copyright (c) 2006 by Tavmjong Bah. All Rights Reserved.
Permission is hereby granted, free of charge, to any person obtaining
a copy of the fonts accompanying this license ("Fonts") and
associated documentation files (the "Font Software"), to reproduce
and distribute the modifications to the Bitstream Vera Font Software,
including without limitation the rights to use, copy, merge, publish,
distribute, and/or sell copies of the Font Software, and to permit
persons to whom the Font Software is furnished to do so, subject to
the following conditions:
The above copyright and trademark notices and this permission notice
shall be included in all copies of one or more of the Font Software
typefaces.
The Font Software may be modified, altered, or added to, and in
particular the designs of glyphs or characters in the Fonts may be
modified and additional glyphs or characters may be added to the
Fonts, only if the fonts are renamed to names not containing either
the words "Tavmjong Bah" or the word "Arev".
This License becomes null and void to the extent applicable to Fonts
or Font Software that has been modified and is distributed under the
"Tavmjong Bah Arev" names.
The Font Software may be sold as part of a larger software package but
no copy of one or more of the Font Software typefaces may be sold by
itself.
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL
TAVMJONG BAH BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.
Except as contained in this notice, the name of Tavmjong Bah shall not
be used in advertising or otherwise to promote the sale, use or other
dealings in this Font Software without prior written authorization
from Tavmjong Bah. For further information, contact: tavmjong @ free
. fr.
$Id: LICENSE 2133 2007-11-28 02:46:28Z lechimp $

View File

@ -137,14 +137,10 @@ void print_regs(struct regs *r) {
kprintf("GS %x, FS %x, ES %x, DS %x\n", r->gs, r->fs, r->es, r->ds);
kprintf("INT NO: %x EFLAGS %x\n", r->int_no, r->eflags);
kprintf("PID: %d CR3 %p USR PAGES AT %p CNT %d\n", current_task->pid, current_task->cr3, current_task->user_pages_at, current_task->user_pages_cnt);
kprintf("KSTACK: 0x%p TASK: %s\n", current_task->kstack, current_task->name);
kprintf("KSTACK: 0x%p USTACK: 0x%p TASK: %s\n", current_task->kstack, current_task->ustack, current_task->name);
//int i;
unsigned int i;
for (i=r->useresp;i<r->useresp + 25;i+=4) {
kprintf("%p, %p\n", i, *(unsigned int *)i);
}
/*
struct task_t *task;
int i, j;

View File

@ -187,24 +187,18 @@ int mem_cpy_pages(struct task_t *old_task, struct task_t *new_task) {
// copy user stack
new_task->user_stack_pages[0] = (unsigned int)mem_alloc_pid(new_task->pid);
new_task->user_stack_pages[1] = (unsigned int)mem_alloc_pid(new_task->pid);
for (i=0;i<USER_STACK_SIZE/0x1000;i++) {
new_task->user_stack_pages[i] = (unsigned int)mem_alloc_pid(new_task->pid);
virt = 0xf0200000;
if (old_task->user_stack_pages[0] != 0) {
mem_map_page(new_task->user_stack_pages[0], (unsigned int)fake_tab, 7);
memcpy((char *)fake_tab, (char *)virt, 0x1000);
virt = 0xf0200000 + i * 0x1000;
if (old_task->user_stack_pages[i] != 0) {
mem_map_page(new_task->user_stack_pages[i], (unsigned int)fake_tab, 7);
memcpy((char *)fake_tab, (char *)virt, 0x1000);
}
mem_map_page_in(new_task->user_stack_pages[i], virt, new_task->cr3, 7);
}
mem_map_page_in(new_task->user_stack_pages[0], virt, new_task->cr3, 7);
virt = 0xf0201000;
if (old_task->user_stack_pages[1] != 0) {
mem_map_page(new_task->user_stack_pages[1], (unsigned int)fake_tab, 7);
memcpy((char *)fake_tab, (char *)virt, 0x1000);
}
mem_map_page_in(new_task->user_stack_pages[1], virt, new_task->cr3, 7);
// copy environment
virt = 0xf0000000;
for (i=0;i<64;i++) {

View File

@ -44,7 +44,6 @@ int main(int argc, char **argv) {
convert_xpm(launcher_xpm, &launcher);
convert_xpm(launchericon_xpm, &icon);
quinn_init();
req = (struct window_req_t *)malloc(sizeof(struct window_req_t));
@ -54,11 +53,11 @@ int main(int argc, char **argv) {
req->height = 350;
req->icon = icon;
strcpy(req->name, "Launcher");
window_handle = quinn_req_window(req);
free(req);
free(icon);
if(!quinn_add_button(window_handle, 25, 105, 100, 50, "Clock", btn_callback1)) {
quinn_exit();
}
@ -72,7 +71,7 @@ int main(int argc, char **argv) {
if (surf == NULL) {
quinn_exit();
}
quinn_render(surf, launcher, 150, 100, 0, 0, 150, 100);
free(launcher);

Binary file not shown.

View File

@ -47,7 +47,7 @@ void convert_xpm(char **xpm, unsigned char **buffer) {
// do colours
unsigned int *theColours = (unsigned int *)malloc(sizeof(unsigned int) * colours);
if (!theColors) {
if (!theColours) {
printf("Out of memory\n");
exit(-1);
}

View File

@ -3,11 +3,18 @@
#include <stdio.h>
#include "quinn.h"
#include "font.h"
#include "convertxpm.h"
#include "scrollup.xpm"
#include "scrolldown.xpm"
#include <ft2build.h>
#include FT_FREETYPE_H
char *default_font="disk0:/fonts/DejaVuSans.ttf";
FT_Library library;
FT_Face ftface;
struct window_blit_req_t {
int wh;
int x;
@ -49,8 +56,6 @@ struct listbox_t {
int scroll_y_offset;
};
extern const struct bitmap_font font;
struct window_t **windows;
int window_count;
@ -83,29 +88,64 @@ void quinn_setpixel(unsigned char *buffer, int x, int y, int dest_w, int dest_h,
}
void quinn_draw_char(unsigned char *buffer, unsigned int dest_width, unsigned int dest_height, unsigned int x, unsigned int y, char c, unsigned int colour) {
int i;
int l;
for (i=0;i<font.Chars;i++) {
if (font.Index[i] == c) break;
}
const char *font_char = &font.Bitmap[i * font.Height];
int cx,cy;
void quinn_draw_char(unsigned char *buffer, unsigned int dest_width, unsigned int dest_height, FT_Int x, FT_Int y, FT_Bitmap *bitmap, unsigned int colour) {
//int mask[8]={1,2,4,8,16,32,64,128};
int mask[8]={128,64,32,16,8,4,2,1};
for(cy=0;cy<13;cy++){
for(cx=0;cx<7;cx++){
if(font_char[cy]&mask[cx]) quinn_setpixel(buffer, x+cx,y+cy, dest_width, dest_height, colour);
int i, j, p, q;
int x_max = x + bitmap->width;
int y_max = y + bitmap->rows;
for (j = y, q = 0; j < y_max; j++, q++) {
for ( i = x, p = 0; i < x_max; i++, p++) {
if (bitmap->buffer[q * bitmap->width + p] > 128) {
quinn_setpixel(buffer, i, j, dest_width, dest_height, colour);
}
}
}
}
void quinn_draw_text(unsigned char *buffer, unsigned int dest_width, unsigned int dest_height, int sx, int sy, unsigned int colour, char *text) {
int quinn_draw_text_width(char *text) {
int i;
FT_GlyphSlot slot;
FT_Error error;
int PenX = 0;
slot = ftface->glyph;
for (i=0;i<strlen(text);i++) {
quinn_draw_char(buffer, dest_width, dest_height, sx + (i * 7), sy, text[i], colour);
if (text[i] == ' ') {
PenX += 8;
continue;
}
error = FT_Load_Char( ftface, text[i], FT_LOAD_RENDER );
if ( error )
continue; /* ignore errors */
PenX += slot->advance.x >> 6;
}
return PenX;
}
void quinn_draw_text(unsigned char *buffer, unsigned int dest_width, unsigned int dest_height, int sx, int sy, unsigned int colour, char *text) {
FT_GlyphSlot slot;
FT_Error error;
int PenX = sx, PenY = sy;
int i;
slot = ftface->glyph;
for (i=0;i<strlen(text);i++) {
if (text[i] == ' ') {
PenX += 8;
continue;
}
error = FT_Load_Char( ftface, text[i], FT_LOAD_RENDER );
if ( error )
continue; /* ignore errors */
quinn_draw_char(buffer, dest_width, dest_height, PenX + slot->bitmap_left, PenY - slot->bitmap_top, &slot->bitmap, colour);
PenX += slot->advance.x >> 6;
PenY += slot->advance.y >> 6; /* not useful for now */
}
}
@ -309,7 +349,14 @@ void quinn_init() {
window_count = 0;
convert_xpm(scrollup_xpm, &scrollup);
convert_xpm(scrolldown_xpm, &scrolldown);
FT_Error error;
error = FT_Init_FreeType(&library);
error = FT_New_Face(library, default_font, 0, &ftface);
error = FT_Set_Char_Size(ftface, 8 * 64, 0, 100, 0);
}
void quinn_draw_listbox(char *surface, struct widget_t *widget, int surf_w, int surf_h) {
struct listbox_t *listbox = widget->widget;
@ -318,12 +365,12 @@ void quinn_draw_listbox(char *surface, struct widget_t *widget, int surf_w, int
quinn_fill_rect(listbox->surface, widget->w, widget->h, 0, 0, widget->w, widget->h, 0xffffff);
for (i=listbox->scroll_y_offset;i<listbox->scroll_y_offset + (widget->h / font.Height) && i < listbox->count;i++) {
for (i=listbox->scroll_y_offset;i<listbox->scroll_y_offset + (widget->h / 8) && i < listbox->count;i++) {
if (listbox->items[i]->selected == 1) {
quinn_fill_rect(listbox->surface, widget->w, widget->h, 0, (i * font.Height) - (listbox->scroll_y_offset * font.Height), widget->w, font.Height, 0xff7ffd);
quinn_draw_text(listbox->surface, widget->w, widget->h, 0, (i * font.Height) - (listbox->scroll_y_offset * font.Height), 0xffffff, listbox->items[i]->name);
quinn_fill_rect(listbox->surface, widget->w, widget->h, 0, (i * 8) - (listbox->scroll_y_offset * 8), widget->w, 8, 0xff7ffd);
quinn_draw_text(listbox->surface, widget->w, widget->h, 0, (i * 8) - (listbox->scroll_y_offset * 8), 0xffffff, listbox->items[i]->name);
} else {
quinn_draw_text(listbox->surface, widget->w, widget->h, 0, (i * font.Height) - (listbox->scroll_y_offset * font.Height), 0, listbox->items[i]->name);
quinn_draw_text(listbox->surface, widget->w, widget->h, 0, (i * 8) - (listbox->scroll_y_offset * 8), 0, listbox->items[i]->name);
}
}
@ -375,7 +422,7 @@ void quinn_draw_button(char *surface, struct widget_t *widget, int surf_w, int s
quinn_fill_rect(surface, surf_w, surf_h, widget->x + 2, widget->y + 2, widget->w - 3, widget->h - 3, 0xd7d7d7);
}
quinn_draw_text(surface, surf_w, surf_h, widget->x + (((widget->w / 2) - (strlen(btn->text) * font.Width) / 2)), widget->y + ((widget->h / 2) - (font.Width / 2)), 0, btn->text);
quinn_draw_text(surface, surf_w, surf_h, widget->x + ((widget->w / 2) - (quinn_draw_text_width(btn->text) / 2)), widget->y + ((widget->h / 2) + (8 / 2)), 0, btn->text);
}
int quinn_process() {
@ -434,7 +481,7 @@ int quinn_process() {
listbox->scroll_y_offset--;
}
} else if (req.mousey - windows[i]->widgets[j]->y > windows[i]->widgets[j]->h - 24 && req.mousey - windows[i]->widgets[j]->y < windows[i]->widgets[j]->h) {
if (listbox->scroll_y_offset < listbox->count - windows[i]->widgets[j]->h % font.Height) {
if (listbox->scroll_y_offset < listbox->count - windows[i]->widgets[j]->h % 8) {
listbox->scroll_y_offset++;
}
}
@ -442,7 +489,7 @@ int quinn_process() {
}
}
int pos = (req.mousey - windows[i]->widgets[j]->y) / font.Height;
int pos = (req.mousey - windows[i]->widgets[j]->y) / 8;
if (!handled) {
if (pos + listbox->scroll_y_offset < listbox->count) {
for (k=0;k<listbox->count;k++) {
@ -464,6 +511,10 @@ int quinn_process() {
void quinn_exit() {
int i;
FT_Done_Face(ftface);
FT_Done_FreeType(library);
for (i=0;i<window_count;i++) {
free(windows[i]->surface);
free(windows[i]);
@ -534,11 +585,11 @@ struct widget_t *quinn_add_listbox(int wh, int x, int y, int w, int h) {
exit(-1);
}
if (h % font.Height > 0) {
h += h % font.Height;
if (h % 20 > 0) {
h += h % 20;
}
if (w % font.Width > 0) {
w += w % font.Width;
if (w % 10 > 0) {
w += w % 10;
}

View File

@ -107,8 +107,9 @@ void init_scheduler(void) {
first_task = current_task;
last_task = current_task;
strcpy(current_task->name, "KERNEL");
current_task->user_stack_pages[0] = 0;
current_task->user_stack_pages[1] = 0;
for (i=0;i<USER_STACK_SIZE/0x1000;i++) {
current_task->user_stack_pages[i] = 0;
}
current_task->user_pages_at = 0x40000000;
current_task->user_pages = (void *)0;
current_task->user_pages_cnt = 0;
@ -261,7 +262,7 @@ struct task_t *sched_new_task() {
new_task->window_count = 0;
new_task->kstack = (unsigned int)(stack_space + KRNL_STACK_SIZE);
new_task->esp = new_task->kstack;
new_task->ustack = 0xf0202000;
new_task->ustack = 0xf0200000 + USER_STACK_SIZE;
new_task->selected_device = current_task->selected_device;
new_task->parent_task = current_task;
new_task->fpu_enabled = 0;

View File

@ -17,7 +17,7 @@
#endif
#ifndef USER_STACK_SIZE
# define USER_STACK_SIZE 0x2000
# define USER_STACK_SIZE 0x16000
#endif
struct semaphore_t {
@ -49,7 +49,7 @@ struct task_t {
unsigned int user_pages_at;
unsigned int user_pages_cnt;
unsigned int *user_pages;
unsigned int user_stack_pages[2];
unsigned int user_stack_pages[USER_STACK_SIZE / 0x1000];
unsigned int user_env_pages[64];
struct vfs_device_t *selected_device;
struct window_t **window_list;