Include the libcroco sources directly under src/st/croco
This is all of the original libcroco, minus these two which we don't use: - cr-sel-eng - the CSS selection engine for xmlNode. - cr-style. Part of https://gitlab.gnome.org/GNOME/gnome-shell/issues/1934
This commit is contained in:
parent
867cffaf20
commit
47758d16ff
@ -18,7 +18,6 @@ cogl_pc = 'mutter-cogl-' + mutter_api_version
|
||||
cogl_pango_pc = 'mutter-cogl-pango-' + mutter_api_version
|
||||
libmutter_pc = 'libmutter-' + mutter_api_version
|
||||
|
||||
croco_req = '>= 0.6.8'
|
||||
ecal_req = '>= 3.33.1'
|
||||
eds_req = '>= 3.17.2'
|
||||
gcr_req = '>= 3.7.5'
|
||||
@ -87,7 +86,6 @@ gio_unix_dep = dependency('gio-unix-2.0', version: gio_req)
|
||||
gjs_dep = dependency('gjs-1.0', version: gjs_req)
|
||||
gtk_dep = dependency('gtk+-3.0', version: gtk_req)
|
||||
libxml_dep = dependency('libxml-2.0')
|
||||
croco_dep = dependency('libcroco-0.6', version: croco_req)
|
||||
clutter_dep = dependency(clutter_pc, version: mutter_req)
|
||||
cogl_dep = dependency(cogl_pc, version: mutter_req)
|
||||
cogl_pango_dep = dependency(cogl_pango_pc, version: mutter_req)
|
||||
|
500
src/st/croco/cr-additional-sel.c
Normal file
500
src/st/croco/cr-additional-sel.c
Normal file
@ -0,0 +1,500 @@
|
||||
/* -*- Mode: C; indent-tabs-mode:nil; c-basic-offset: 8-*- */
|
||||
|
||||
/*
|
||||
* This file is part of The Croco Library
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of version 2.1 of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*
|
||||
* Author: Dodji Seketeli
|
||||
* See COPYRIGHTS file for copyright information.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "cr-additional-sel.h"
|
||||
#include "string.h"
|
||||
|
||||
/**
|
||||
* CRAdditionalSel:
|
||||
*
|
||||
* #CRAdditionalSel abstracts an additionnal selector.
|
||||
* An additional selector is the selector part
|
||||
* that comes after the combination of type selectors.
|
||||
* It can be either "a class selector (the .class part),
|
||||
* a pseudo class selector, an attribute selector
|
||||
* or an id selector.
|
||||
*/
|
||||
|
||||
/**
|
||||
* cr_additional_sel_new:
|
||||
*
|
||||
* Default constructor of #CRAdditionalSel.
|
||||
* Returns the newly build instance of #CRAdditionalSel.
|
||||
*/
|
||||
CRAdditionalSel *
|
||||
cr_additional_sel_new (void)
|
||||
{
|
||||
CRAdditionalSel *result = NULL;
|
||||
|
||||
result = g_try_malloc (sizeof (CRAdditionalSel));
|
||||
|
||||
if (result == NULL) {
|
||||
cr_utils_trace_debug ("Out of memory");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset (result, 0, sizeof (CRAdditionalSel));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_additional_sel_new_with_type:
|
||||
* @a_sel_type: the type of the newly built instance
|
||||
* of #CRAdditionalSel.
|
||||
*
|
||||
* Constructor of #CRAdditionalSel.
|
||||
* Returns the newly built instance of #CRAdditionalSel.
|
||||
*/
|
||||
CRAdditionalSel *
|
||||
cr_additional_sel_new_with_type (enum AddSelectorType a_sel_type)
|
||||
{
|
||||
CRAdditionalSel *result = NULL;
|
||||
|
||||
result = cr_additional_sel_new ();
|
||||
|
||||
g_return_val_if_fail (result, NULL);
|
||||
|
||||
result->type = a_sel_type;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_additional_sel_set_class_name:
|
||||
* @a_this: the "this pointer" of the current instance
|
||||
* of #CRAdditionalSel .
|
||||
* @a_class_name: the new class name to set.
|
||||
*
|
||||
* Sets a new class name to a
|
||||
* CLASS additional selector.
|
||||
*/
|
||||
void
|
||||
cr_additional_sel_set_class_name (CRAdditionalSel * a_this,
|
||||
CRString * a_class_name)
|
||||
{
|
||||
g_return_if_fail (a_this && a_this->type == CLASS_ADD_SELECTOR);
|
||||
|
||||
if (a_this->content.class_name) {
|
||||
cr_string_destroy (a_this->content.class_name);
|
||||
}
|
||||
|
||||
a_this->content.class_name = a_class_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_additional_sel_set_id_name:
|
||||
* @a_this: the "this pointer" of the current instance
|
||||
* of #CRAdditionalSel .
|
||||
* @a_id: the new id to set.
|
||||
*
|
||||
* Sets a new id name to an
|
||||
* ID additional selector.
|
||||
*/
|
||||
void
|
||||
cr_additional_sel_set_id_name (CRAdditionalSel * a_this, CRString * a_id)
|
||||
{
|
||||
g_return_if_fail (a_this && a_this->type == ID_ADD_SELECTOR);
|
||||
|
||||
if (a_this->content.id_name) {
|
||||
cr_string_destroy (a_this->content.id_name);
|
||||
}
|
||||
|
||||
a_this->content.id_name = a_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_additional_sel_set_pseudo:
|
||||
* @a_this: the "this pointer" of the current instance
|
||||
* of #CRAdditionalSel .
|
||||
* @a_pseudo: the new pseudo to set.
|
||||
*
|
||||
* Sets a new pseudo to a
|
||||
* PSEUDO additional selector.
|
||||
*/
|
||||
void
|
||||
cr_additional_sel_set_pseudo (CRAdditionalSel * a_this, CRPseudo * a_pseudo)
|
||||
{
|
||||
g_return_if_fail (a_this
|
||||
&& a_this->type == PSEUDO_CLASS_ADD_SELECTOR);
|
||||
|
||||
if (a_this->content.pseudo) {
|
||||
cr_pseudo_destroy (a_this->content.pseudo);
|
||||
}
|
||||
|
||||
a_this->content.pseudo = a_pseudo;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_additional_sel_set_attr_sel:
|
||||
* @a_this: the "this pointer" of the current instance
|
||||
* of #CRAdditionalSel .
|
||||
* @a_sel: the new instance of #CRAttrSel to set.
|
||||
*
|
||||
* Sets a new instance of #CRAttrSel to
|
||||
* a ATTRIBUTE additional selector.
|
||||
*/
|
||||
void
|
||||
cr_additional_sel_set_attr_sel (CRAdditionalSel * a_this, CRAttrSel * a_sel)
|
||||
{
|
||||
g_return_if_fail (a_this && a_this->type == ATTRIBUTE_ADD_SELECTOR);
|
||||
|
||||
if (a_this->content.attr_sel) {
|
||||
cr_attr_sel_destroy (a_this->content.attr_sel);
|
||||
}
|
||||
|
||||
a_this->content.attr_sel = a_sel;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_additional_sel_append:
|
||||
* @a_this: the "this pointer" of the current instance
|
||||
* of #CRAdditionalSel .
|
||||
* @a_sel: the new instance to #CRAdditional to append.
|
||||
*
|
||||
* Appends a new instance of #CRAdditional to the
|
||||
* current list of #CRAdditional.
|
||||
*
|
||||
* Returns the new list of CRAdditionalSel or NULL if an error arises.
|
||||
*/
|
||||
CRAdditionalSel *
|
||||
cr_additional_sel_append (CRAdditionalSel * a_this, CRAdditionalSel * a_sel)
|
||||
{
|
||||
CRAdditionalSel *cur_sel = NULL;
|
||||
|
||||
g_return_val_if_fail (a_sel, NULL);
|
||||
|
||||
if (a_this == NULL) {
|
||||
return a_sel;
|
||||
}
|
||||
|
||||
if (a_sel == NULL)
|
||||
return NULL;
|
||||
|
||||
for (cur_sel = a_this;
|
||||
cur_sel && cur_sel->next; cur_sel = cur_sel->next) ;
|
||||
|
||||
g_return_val_if_fail (cur_sel != NULL, NULL);
|
||||
|
||||
cur_sel->next = a_sel;
|
||||
a_sel->prev = cur_sel;
|
||||
|
||||
return a_this;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_additional_sel_prepend:
|
||||
* @a_this: the "this pointer" of the current instance
|
||||
* of #CRAdditionalSel .
|
||||
* @a_sel: the new instance to #CRAdditional to preappend.
|
||||
*
|
||||
* Preppends a new instance of #CRAdditional to the
|
||||
* current list of #CRAdditional.
|
||||
*
|
||||
* Returns the new list of CRAdditionalSel or NULL if an error arises.
|
||||
*/
|
||||
CRAdditionalSel *
|
||||
cr_additional_sel_prepend (CRAdditionalSel * a_this, CRAdditionalSel * a_sel)
|
||||
{
|
||||
g_return_val_if_fail (a_sel, NULL);
|
||||
|
||||
if (a_this == NULL) {
|
||||
return a_sel;
|
||||
}
|
||||
|
||||
a_sel->next = a_this;
|
||||
a_this->prev = a_sel;
|
||||
|
||||
return a_sel;
|
||||
}
|
||||
|
||||
guchar *
|
||||
cr_additional_sel_to_string (CRAdditionalSel const * a_this)
|
||||
{
|
||||
guchar *result = NULL;
|
||||
GString *str_buf = NULL;
|
||||
CRAdditionalSel const *cur = NULL;
|
||||
|
||||
g_return_val_if_fail (a_this, NULL);
|
||||
|
||||
str_buf = g_string_new (NULL);
|
||||
|
||||
for (cur = a_this; cur; cur = cur->next) {
|
||||
switch (cur->type) {
|
||||
case CLASS_ADD_SELECTOR:
|
||||
{
|
||||
guchar *name = NULL;
|
||||
|
||||
if (cur->content.class_name) {
|
||||
name = (guchar *) g_strndup
|
||||
(cur->content.class_name->stryng->str,
|
||||
cur->content.class_name->stryng->len);
|
||||
|
||||
if (name) {
|
||||
g_string_append_printf
|
||||
(str_buf, ".%s",
|
||||
name);
|
||||
g_free (name);
|
||||
name = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case ID_ADD_SELECTOR:
|
||||
{
|
||||
guchar *name = NULL;
|
||||
|
||||
if (cur->content.id_name) {
|
||||
name = (guchar *) g_strndup
|
||||
(cur->content.id_name->stryng->str,
|
||||
cur->content.id_name->stryng->len);
|
||||
|
||||
if (name) {
|
||||
g_string_append_printf
|
||||
(str_buf, "#%s",
|
||||
name);
|
||||
g_free (name);
|
||||
name = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case PSEUDO_CLASS_ADD_SELECTOR:
|
||||
{
|
||||
if (cur->content.pseudo) {
|
||||
guchar *tmp_str = NULL;
|
||||
|
||||
tmp_str = cr_pseudo_to_string
|
||||
(cur->content.pseudo);
|
||||
if (tmp_str) {
|
||||
g_string_append_printf
|
||||
(str_buf, ":%s",
|
||||
tmp_str);
|
||||
g_free (tmp_str);
|
||||
tmp_str = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case ATTRIBUTE_ADD_SELECTOR:
|
||||
if (cur->content.attr_sel) {
|
||||
guchar *tmp_str = NULL;
|
||||
|
||||
g_string_append_c (str_buf, '[');
|
||||
tmp_str = cr_attr_sel_to_string
|
||||
(cur->content.attr_sel);
|
||||
if (tmp_str) {
|
||||
g_string_append_printf
|
||||
(str_buf, "%s]", tmp_str);
|
||||
g_free (tmp_str);
|
||||
tmp_str = NULL;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (str_buf) {
|
||||
result = (guchar *) str_buf->str;
|
||||
g_string_free (str_buf, FALSE);
|
||||
str_buf = NULL;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
guchar *
|
||||
cr_additional_sel_one_to_string (CRAdditionalSel const *a_this)
|
||||
{
|
||||
guchar *result = NULL;
|
||||
GString *str_buf = NULL;
|
||||
|
||||
g_return_val_if_fail (a_this, NULL) ;
|
||||
|
||||
str_buf = g_string_new (NULL) ;
|
||||
|
||||
switch (a_this->type) {
|
||||
case CLASS_ADD_SELECTOR:
|
||||
{
|
||||
guchar *name = NULL;
|
||||
|
||||
if (a_this->content.class_name) {
|
||||
name = (guchar *) g_strndup
|
||||
(a_this->content.class_name->stryng->str,
|
||||
a_this->content.class_name->stryng->len);
|
||||
|
||||
if (name) {
|
||||
g_string_append_printf
|
||||
(str_buf, ".%s",
|
||||
name);
|
||||
g_free (name);
|
||||
name = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case ID_ADD_SELECTOR:
|
||||
{
|
||||
guchar *name = NULL;
|
||||
|
||||
if (a_this->content.id_name) {
|
||||
name = (guchar *) g_strndup
|
||||
(a_this->content.id_name->stryng->str,
|
||||
a_this->content.id_name->stryng->len);
|
||||
|
||||
if (name) {
|
||||
g_string_append_printf
|
||||
(str_buf, "#%s",
|
||||
name);
|
||||
g_free (name);
|
||||
name = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case PSEUDO_CLASS_ADD_SELECTOR:
|
||||
{
|
||||
if (a_this->content.pseudo) {
|
||||
guchar *tmp_str = NULL;
|
||||
|
||||
tmp_str = cr_pseudo_to_string
|
||||
(a_this->content.pseudo);
|
||||
if (tmp_str) {
|
||||
g_string_append_printf
|
||||
(str_buf, ":%s",
|
||||
tmp_str);
|
||||
g_free (tmp_str);
|
||||
tmp_str = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case ATTRIBUTE_ADD_SELECTOR:
|
||||
if (a_this->content.attr_sel) {
|
||||
guchar *tmp_str = NULL;
|
||||
|
||||
g_string_append_printf (str_buf, "[");
|
||||
tmp_str = cr_attr_sel_to_string
|
||||
(a_this->content.attr_sel);
|
||||
if (tmp_str) {
|
||||
g_string_append_printf
|
||||
(str_buf, "%s]", tmp_str);
|
||||
g_free (tmp_str);
|
||||
tmp_str = NULL;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (str_buf) {
|
||||
result = (guchar *) str_buf->str;
|
||||
g_string_free (str_buf, FALSE);
|
||||
str_buf = NULL;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_additional_sel_dump:
|
||||
* @a_this: the "this pointer" of the current instance of
|
||||
* #CRAdditionalSel.
|
||||
* @a_fp: the destination file.
|
||||
*
|
||||
* Dumps the current instance of #CRAdditionalSel to a file
|
||||
*/
|
||||
void
|
||||
cr_additional_sel_dump (CRAdditionalSel const * a_this, FILE * a_fp)
|
||||
{
|
||||
guchar *tmp_str = NULL;
|
||||
|
||||
g_return_if_fail (a_fp);
|
||||
|
||||
if (a_this) {
|
||||
tmp_str = cr_additional_sel_to_string (a_this);
|
||||
if (tmp_str) {
|
||||
fprintf (a_fp, "%s", tmp_str);
|
||||
g_free (tmp_str);
|
||||
tmp_str = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_additional_sel_destroy:
|
||||
* @a_this: the "this pointer" of the current instance
|
||||
* of #CRAdditionalSel .
|
||||
*
|
||||
* Destroys an instance of #CRAdditional.
|
||||
*/
|
||||
void
|
||||
cr_additional_sel_destroy (CRAdditionalSel * a_this)
|
||||
{
|
||||
g_return_if_fail (a_this);
|
||||
|
||||
switch (a_this->type) {
|
||||
case CLASS_ADD_SELECTOR:
|
||||
cr_string_destroy (a_this->content.class_name);
|
||||
a_this->content.class_name = NULL;
|
||||
break;
|
||||
|
||||
case PSEUDO_CLASS_ADD_SELECTOR:
|
||||
cr_pseudo_destroy (a_this->content.pseudo);
|
||||
a_this->content.pseudo = NULL;
|
||||
break;
|
||||
|
||||
case ID_ADD_SELECTOR:
|
||||
cr_string_destroy (a_this->content.id_name);
|
||||
a_this->content.id_name = NULL;
|
||||
break;
|
||||
|
||||
case ATTRIBUTE_ADD_SELECTOR:
|
||||
cr_attr_sel_destroy (a_this->content.attr_sel);
|
||||
a_this->content.attr_sel = NULL;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (a_this->next) {
|
||||
cr_additional_sel_destroy (a_this->next);
|
||||
}
|
||||
|
||||
g_free (a_this);
|
||||
}
|
98
src/st/croco/cr-additional-sel.h
Normal file
98
src/st/croco/cr-additional-sel.h
Normal file
@ -0,0 +1,98 @@
|
||||
/* -*- Mode: C; indent-tabs-mode:nil; c-basic-offset: 8-*- */
|
||||
|
||||
/*
|
||||
* This file is part of The Croco Library
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of version 2.1 of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*
|
||||
* Author: Dodji Seketeli
|
||||
* See the COPYRIGHTS file for copyright information.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __CR_ADD_SEL_H__
|
||||
#define __CR_ADD_SEL_H__
|
||||
|
||||
#include <stdio.h>
|
||||
#include <glib.h>
|
||||
#include "cr-utils.h"
|
||||
#include "cr-attr-sel.h"
|
||||
#include "cr-pseudo.h"
|
||||
#include "cr-additional-sel.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
enum AddSelectorType
|
||||
{
|
||||
NO_ADD_SELECTOR = 0 ,
|
||||
CLASS_ADD_SELECTOR = 1 ,
|
||||
PSEUDO_CLASS_ADD_SELECTOR = 1 << 1,
|
||||
ID_ADD_SELECTOR = 1 << 3,
|
||||
ATTRIBUTE_ADD_SELECTOR = 1 << 4
|
||||
} ;
|
||||
|
||||
union CRAdditionalSelectorContent
|
||||
{
|
||||
CRString *class_name ;
|
||||
CRString *id_name ;
|
||||
CRPseudo *pseudo ;
|
||||
CRAttrSel *attr_sel ;
|
||||
} ;
|
||||
|
||||
typedef struct _CRAdditionalSel CRAdditionalSel ;
|
||||
|
||||
struct _CRAdditionalSel
|
||||
{
|
||||
enum AddSelectorType type ;
|
||||
union CRAdditionalSelectorContent content ;
|
||||
|
||||
CRAdditionalSel * next ;
|
||||
CRAdditionalSel * prev ;
|
||||
CRParsingLocation location ;
|
||||
} ;
|
||||
|
||||
CRAdditionalSel * cr_additional_sel_new (void) ;
|
||||
|
||||
CRAdditionalSel * cr_additional_sel_new_with_type (enum AddSelectorType a_sel_type) ;
|
||||
|
||||
CRAdditionalSel * cr_additional_sel_append (CRAdditionalSel *a_this,
|
||||
CRAdditionalSel *a_sel) ;
|
||||
|
||||
void cr_additional_sel_set_class_name (CRAdditionalSel *a_this,
|
||||
CRString *a_class_name) ;
|
||||
|
||||
void cr_additional_sel_set_id_name (CRAdditionalSel *a_this,
|
||||
CRString *a_id) ;
|
||||
|
||||
void cr_additional_sel_set_pseudo (CRAdditionalSel *a_this,
|
||||
CRPseudo *a_pseudo) ;
|
||||
|
||||
void cr_additional_sel_set_attr_sel (CRAdditionalSel *a_this,
|
||||
CRAttrSel *a_sel) ;
|
||||
|
||||
CRAdditionalSel * cr_additional_sel_prepend (CRAdditionalSel *a_this,
|
||||
CRAdditionalSel *a_sel) ;
|
||||
|
||||
guchar * cr_additional_sel_to_string (CRAdditionalSel const *a_this) ;
|
||||
|
||||
guchar * cr_additional_sel_one_to_string (CRAdditionalSel const *a_this) ;
|
||||
|
||||
void cr_additional_sel_dump (CRAdditionalSel const *a_this, FILE *a_fp) ;
|
||||
|
||||
void cr_additional_sel_destroy (CRAdditionalSel *a_this) ;
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /*__CR_ADD_SEL_H*/
|
235
src/st/croco/cr-attr-sel.c
Normal file
235
src/st/croco/cr-attr-sel.c
Normal file
@ -0,0 +1,235 @@
|
||||
/* -*- Mode: C; indent-tabs-mode:nil; c-basic-offset: 8-*- */
|
||||
|
||||
/*
|
||||
* This file is part of The Croco Library
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of version 2.1 of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*
|
||||
* See COPYRIGHTS file for copyrights information.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "cr-attr-sel.h"
|
||||
|
||||
/**
|
||||
* CRAttrSel:
|
||||
*
|
||||
* #CRAdditionalSel abstracts an attribute selector.
|
||||
* Attributes selectors are described in the css2 spec [5.8].
|
||||
* There are more generally used in the css2 selectors described in
|
||||
* css2 spec [5] .
|
||||
*/
|
||||
|
||||
/**
|
||||
* cr_attr_sel_new:
|
||||
* The constructor of #CRAttrSel.
|
||||
* Returns the newly allocated instance
|
||||
* of #CRAttrSel.
|
||||
*/
|
||||
CRAttrSel *
|
||||
cr_attr_sel_new (void)
|
||||
{
|
||||
CRAttrSel *result = NULL;
|
||||
|
||||
result = g_malloc0 (sizeof (CRAttrSel));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_attr_sel_append_attr_sel:
|
||||
* @a_this: the this pointer of the current instance of #CRAttrSel.
|
||||
* @a_attr_sel: selector to append.
|
||||
*
|
||||
* Appends an attribute selector to the current list of
|
||||
* attribute selectors represented by a_this.
|
||||
* Returns CR_OK upon successfull completion, an error code otherwise.
|
||||
*/
|
||||
enum CRStatus
|
||||
cr_attr_sel_append_attr_sel (CRAttrSel * a_this, CRAttrSel * a_attr_sel)
|
||||
{
|
||||
CRAttrSel *cur_sel = NULL;
|
||||
|
||||
g_return_val_if_fail (a_this && a_attr_sel,
|
||||
CR_BAD_PARAM_ERROR);
|
||||
|
||||
for (cur_sel = a_this;
|
||||
cur_sel->next;
|
||||
cur_sel = cur_sel->next) ;
|
||||
|
||||
cur_sel->next = a_attr_sel;
|
||||
a_attr_sel->prev = cur_sel;
|
||||
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_attr_sel_prepend_attr_sel:
|
||||
*@a_this: the "this pointer" of the current instance *of #CRAttrSel.
|
||||
*@a_attr_sel: the attribute selector to append.
|
||||
*
|
||||
*Prepends an attribute selector to the list of
|
||||
*attributes selector represented by a_this.
|
||||
*Returns CR_OK upon successfull completion, an error code otherwise.
|
||||
*/
|
||||
enum CRStatus
|
||||
cr_attr_sel_prepend_attr_sel (CRAttrSel * a_this,
|
||||
CRAttrSel * a_attr_sel)
|
||||
{
|
||||
g_return_val_if_fail (a_this && a_attr_sel,
|
||||
CR_BAD_PARAM_ERROR);
|
||||
|
||||
a_attr_sel->next = a_this;
|
||||
a_this->prev = a_attr_sel;
|
||||
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_attr_sel_to_string:
|
||||
* @a_this: the current instance of #CRAttrSel.
|
||||
*
|
||||
* Serializes an attribute selector into a string
|
||||
* Returns the serialized attribute selector.
|
||||
*/
|
||||
guchar *
|
||||
cr_attr_sel_to_string (CRAttrSel const * a_this)
|
||||
{
|
||||
CRAttrSel const *cur = NULL;
|
||||
guchar *result = NULL;
|
||||
GString *str_buf = NULL;
|
||||
|
||||
g_return_val_if_fail (a_this, NULL);
|
||||
|
||||
str_buf = g_string_new (NULL);
|
||||
|
||||
for (cur = a_this; cur; cur = cur->next) {
|
||||
if (cur->prev) {
|
||||
g_string_append_c (str_buf, ' ');
|
||||
}
|
||||
|
||||
if (cur->name) {
|
||||
guchar *name = NULL;
|
||||
|
||||
name = (guchar *) g_strndup (cur->name->stryng->str,
|
||||
cur->name->stryng->len);
|
||||
if (name) {
|
||||
g_string_append (str_buf, (const gchar *) name);
|
||||
g_free (name);
|
||||
name = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (cur->value) {
|
||||
guchar *value = NULL;
|
||||
|
||||
value = (guchar *) g_strndup (cur->value->stryng->str,
|
||||
cur->value->stryng->len);
|
||||
if (value) {
|
||||
switch (cur->match_way) {
|
||||
case SET:
|
||||
break;
|
||||
|
||||
case EQUALS:
|
||||
g_string_append_c (str_buf, '=');
|
||||
break;
|
||||
|
||||
case INCLUDES:
|
||||
g_string_append (str_buf, "~=");
|
||||
break;
|
||||
|
||||
case DASHMATCH:
|
||||
g_string_append (str_buf, "|=");
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
g_string_append_printf
|
||||
(str_buf, "\"%s\"", value);
|
||||
|
||||
g_free (value);
|
||||
value = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (str_buf) {
|
||||
result = (guchar *) str_buf->str;
|
||||
g_string_free (str_buf, FALSE);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_attr_sel_dump:
|
||||
* @a_this: the "this pointer" of the current instance of
|
||||
* #CRAttrSel.
|
||||
* @a_fp: the destination file.
|
||||
*
|
||||
* Dumps the current instance of #CRAttrSel to a file.
|
||||
*/
|
||||
void
|
||||
cr_attr_sel_dump (CRAttrSel const * a_this, FILE * a_fp)
|
||||
{
|
||||
guchar *tmp_str = NULL;
|
||||
|
||||
g_return_if_fail (a_this);
|
||||
|
||||
tmp_str = cr_attr_sel_to_string (a_this);
|
||||
|
||||
if (tmp_str) {
|
||||
fprintf (a_fp, "%s", tmp_str);
|
||||
g_free (tmp_str);
|
||||
tmp_str = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*cr_attr_sel_destroy:
|
||||
*@a_this: the "this pointer" of the current
|
||||
*instance of #CRAttrSel.
|
||||
*
|
||||
*Destroys the current instance of #CRAttrSel.
|
||||
*Frees all the fields if they are non null.
|
||||
*/
|
||||
void
|
||||
cr_attr_sel_destroy (CRAttrSel * a_this)
|
||||
{
|
||||
g_return_if_fail (a_this);
|
||||
|
||||
if (a_this->name) {
|
||||
cr_string_destroy (a_this->name);
|
||||
a_this->name = NULL;
|
||||
}
|
||||
|
||||
if (a_this->value) {
|
||||
cr_string_destroy (a_this->value);
|
||||
a_this->value = NULL;
|
||||
}
|
||||
|
||||
if (a_this->next) {
|
||||
cr_attr_sel_destroy (a_this->next);
|
||||
a_this->next = NULL;
|
||||
}
|
||||
|
||||
if (a_this) {
|
||||
g_free (a_this);
|
||||
a_this = NULL;
|
||||
}
|
||||
}
|
||||
|
74
src/st/croco/cr-attr-sel.h
Normal file
74
src/st/croco/cr-attr-sel.h
Normal file
@ -0,0 +1,74 @@
|
||||
/* -*- Mode: C; indent-tabs-mode:nil; c-basic-offset: 8-*- */
|
||||
|
||||
/*
|
||||
* This file is part of The Croco Library
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of version 2.1 of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*
|
||||
* Author: Dodji Seketeli
|
||||
* See COPYRIGHTS file for copyright information.
|
||||
*/
|
||||
|
||||
#ifndef __CR_ATTR_SEL_H__
|
||||
#define __CR_ATTR_SEL_H__
|
||||
|
||||
#include <stdio.h>
|
||||
#include <glib.h>
|
||||
#include "cr-utils.h"
|
||||
#include "cr-parsing-location.h"
|
||||
#include "cr-string.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
||||
struct _CRAttrSel ;
|
||||
typedef struct _CRAttrSel CRAttrSel ;
|
||||
|
||||
enum AttrMatchWay
|
||||
{
|
||||
NO_MATCH = 0,
|
||||
SET,
|
||||
EQUALS,
|
||||
INCLUDES,
|
||||
DASHMATCH
|
||||
} ;
|
||||
|
||||
struct _CRAttrSel
|
||||
{
|
||||
CRString *name ;
|
||||
CRString *value ;
|
||||
enum AttrMatchWay match_way ;
|
||||
CRAttrSel *next ;
|
||||
CRAttrSel *prev ;
|
||||
CRParsingLocation location ;
|
||||
} ;
|
||||
|
||||
CRAttrSel * cr_attr_sel_new (void) ;
|
||||
|
||||
enum CRStatus cr_attr_sel_append_attr_sel (CRAttrSel * a_this,
|
||||
CRAttrSel *a_attr_sel) ;
|
||||
|
||||
enum CRStatus cr_attr_sel_prepend_attr_sel (CRAttrSel *a_this,
|
||||
CRAttrSel *a_attr_sel) ;
|
||||
|
||||
guchar * cr_attr_sel_to_string (CRAttrSel const *a_this) ;
|
||||
|
||||
void cr_attr_sel_dump (CRAttrSel const *a_this, FILE *a_fp) ;
|
||||
|
||||
void cr_attr_sel_destroy (CRAttrSel *a_this) ;
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /*__CR_ATTR_SEL_H__*/
|
215
src/st/croco/cr-cascade.c
Normal file
215
src/st/croco/cr-cascade.c
Normal file
@ -0,0 +1,215 @@
|
||||
/* -*- Mode: C; indent-tabs-mode:nil; c-basic-offset: 8-*- */
|
||||
|
||||
/*
|
||||
* This file is part of The Croco Library
|
||||
*
|
||||
* Copyright (C) 2002-2003 Dodji Seketeli <dodji@seketeli.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of version 2.1 of the
|
||||
* GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the
|
||||
* GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*/
|
||||
|
||||
/*
|
||||
*$Id$
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "cr-cascade.h"
|
||||
|
||||
#define PRIVATE(a_this) ((a_this)->priv)
|
||||
|
||||
struct _CRCascadePriv {
|
||||
/**
|
||||
*the 3 style sheets of the cascade:
|
||||
*author, user, and useragent sheet.
|
||||
*Intended to be addressed by
|
||||
*sheets[ORIGIN_AUTHOR] or sheets[ORIGIN_USER]
|
||||
*of sheets[ORIGIN_UA] ;
|
||||
*/
|
||||
CRStyleSheet *sheets[3];
|
||||
guint ref_count;
|
||||
};
|
||||
|
||||
/**
|
||||
* cr_cascade_new:
|
||||
*@a_author_sheet: the author origin style sheet. May be NULL.
|
||||
*@a_user_sheet: the user origin style sheet. May be NULL.
|
||||
*@a_ua_sheet: the user agent origin style sheet. May be NULL.
|
||||
*
|
||||
*Constructor of the #CRCascade class.
|
||||
*Note that all three parameters of this
|
||||
*method are ref counted and their refcount is increased.
|
||||
*Their refcount will be decreased at the destruction of
|
||||
*the instance of #CRCascade.
|
||||
*So the caller should not call their destructor. The caller
|
||||
*should call their ref/unref method instead if it wants
|
||||
*
|
||||
*Returns the newly built instance of CRCascade or NULL if
|
||||
*an error arose during constrution.
|
||||
*/
|
||||
CRCascade *
|
||||
cr_cascade_new (CRStyleSheet * a_author_sheet,
|
||||
CRStyleSheet * a_user_sheet, CRStyleSheet * a_ua_sheet)
|
||||
{
|
||||
CRCascade *result = NULL;
|
||||
|
||||
result = g_try_malloc (sizeof (CRCascade));
|
||||
if (!result) {
|
||||
cr_utils_trace_info ("Out of memory");
|
||||
return NULL;
|
||||
}
|
||||
memset (result, 0, sizeof (CRCascade));
|
||||
|
||||
PRIVATE (result) = g_try_malloc (sizeof (CRCascadePriv));
|
||||
if (!PRIVATE (result)) {
|
||||
cr_utils_trace_info ("Out of memory");
|
||||
g_free (result);
|
||||
return NULL;
|
||||
}
|
||||
memset (PRIVATE (result), 0, sizeof (CRCascadePriv));
|
||||
|
||||
if (a_author_sheet) {
|
||||
cr_cascade_set_sheet (result, a_author_sheet, ORIGIN_AUTHOR);
|
||||
}
|
||||
if (a_user_sheet) {
|
||||
cr_cascade_set_sheet (result, a_user_sheet, ORIGIN_USER);
|
||||
}
|
||||
if (a_ua_sheet) {
|
||||
cr_cascade_set_sheet (result, a_ua_sheet, ORIGIN_UA);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_cascade_get_sheet:
|
||||
*@a_this: the current instance of #CRCascade.
|
||||
*@a_origin: the origin of the style sheet as
|
||||
*defined in the css2 spec in chapter 6.4.
|
||||
*Gets a given origin sheet.
|
||||
*
|
||||
*Gets a sheet, part of the cascade.
|
||||
*Note that the returned stylesheet
|
||||
*is refcounted so if the caller wants
|
||||
*to manage it's lifecycle, it must use
|
||||
*cr_stylesheet_ref()/cr_stylesheet_unref() instead
|
||||
*of the cr_stylesheet_destroy() method.
|
||||
*Returns the style sheet, or NULL if it does not
|
||||
*exist.
|
||||
*/
|
||||
CRStyleSheet *
|
||||
cr_cascade_get_sheet (CRCascade * a_this, enum CRStyleOrigin a_origin)
|
||||
{
|
||||
g_return_val_if_fail (a_this
|
||||
&& a_origin >= ORIGIN_UA
|
||||
&& a_origin < NB_ORIGINS, NULL);
|
||||
|
||||
return PRIVATE (a_this)->sheets[a_origin];
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_cascade_set_sheet:
|
||||
*@a_this: the current instance of #CRCascade.
|
||||
*@a_sheet: the stylesheet to set.
|
||||
*@a_origin: the origin of the stylesheet.
|
||||
*
|
||||
*Sets a stylesheet in the cascade
|
||||
*
|
||||
*Returns CR_OK upon successfull completion, an error
|
||||
*code otherwise.
|
||||
*/
|
||||
enum CRStatus
|
||||
cr_cascade_set_sheet (CRCascade * a_this,
|
||||
CRStyleSheet * a_sheet, enum CRStyleOrigin a_origin)
|
||||
{
|
||||
g_return_val_if_fail (a_this
|
||||
&& a_sheet
|
||||
&& a_origin >= ORIGIN_UA
|
||||
&& a_origin < NB_ORIGINS, CR_BAD_PARAM_ERROR);
|
||||
|
||||
if (PRIVATE (a_this)->sheets[a_origin])
|
||||
cr_stylesheet_unref (PRIVATE (a_this)->sheets[a_origin]);
|
||||
PRIVATE (a_this)->sheets[a_origin] = a_sheet;
|
||||
cr_stylesheet_ref (a_sheet);
|
||||
a_sheet->origin = a_origin;
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
*cr_cascade_ref:
|
||||
*@a_this: the current instance of #CRCascade
|
||||
*
|
||||
*Increases the reference counter of the current instance
|
||||
*of #CRCascade.
|
||||
*/
|
||||
void
|
||||
cr_cascade_ref (CRCascade * a_this)
|
||||
{
|
||||
g_return_if_fail (a_this && PRIVATE (a_this));
|
||||
|
||||
PRIVATE (a_this)->ref_count++;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_cascade_unref:
|
||||
*@a_this: the current instance of
|
||||
*#CRCascade.
|
||||
*
|
||||
*Decrements the reference counter associated
|
||||
*to this instance of #CRCascade. If the reference
|
||||
*counter reaches zero, the instance is destroyed
|
||||
*using cr_cascade_destroy()
|
||||
*/
|
||||
void
|
||||
cr_cascade_unref (CRCascade * a_this)
|
||||
{
|
||||
g_return_if_fail (a_this && PRIVATE (a_this));
|
||||
|
||||
if (PRIVATE (a_this)->ref_count)
|
||||
PRIVATE (a_this)->ref_count--;
|
||||
if (!PRIVATE (a_this)->ref_count) {
|
||||
cr_cascade_destroy (a_this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_cascade_destroy:
|
||||
* @a_this: the current instance of #CRCascade
|
||||
*
|
||||
* Destructor of #CRCascade.
|
||||
*/
|
||||
void
|
||||
cr_cascade_destroy (CRCascade * a_this)
|
||||
{
|
||||
g_return_if_fail (a_this);
|
||||
|
||||
if (PRIVATE (a_this)) {
|
||||
gulong i = 0;
|
||||
|
||||
for (i = 0; PRIVATE (a_this)->sheets && i < NB_ORIGINS; i++) {
|
||||
if (PRIVATE (a_this)->sheets[i]) {
|
||||
if (cr_stylesheet_unref
|
||||
(PRIVATE (a_this)->sheets[i])
|
||||
== TRUE) {
|
||||
PRIVATE (a_this)->sheets[i] = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
g_free (PRIVATE (a_this));
|
||||
PRIVATE (a_this) = NULL;
|
||||
}
|
||||
g_free (a_this);
|
||||
}
|
74
src/st/croco/cr-cascade.h
Normal file
74
src/st/croco/cr-cascade.h
Normal file
@ -0,0 +1,74 @@
|
||||
/* -*- Mode: C; indent-tabs-mode:nil; c-basic-offset: 8-*- */
|
||||
|
||||
/*
|
||||
* This file is part of The Croco Library
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of version 2.1 of the
|
||||
* GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the
|
||||
* GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
*$Id$
|
||||
*/
|
||||
|
||||
#ifndef __CR_CASCADE_H__
|
||||
#define __CR_CASCADE_H__
|
||||
|
||||
#include "cr-stylesheet.h"
|
||||
|
||||
/**
|
||||
*@file
|
||||
*the declaration of the #CRCascade class.
|
||||
*/
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
||||
typedef struct _CRCascadePriv CRCascadePriv ;
|
||||
|
||||
/**
|
||||
*An abstraction of the "Cascade" defined
|
||||
*in the css2 spec, chapter 6.4.
|
||||
*/
|
||||
typedef struct _CRCascade CRCascade ;
|
||||
|
||||
struct _CRCascade
|
||||
{
|
||||
CRCascadePriv *priv ;
|
||||
};
|
||||
|
||||
|
||||
CRCascade * cr_cascade_new (CRStyleSheet *a_author_sheet,
|
||||
CRStyleSheet *a_user_sheet,
|
||||
CRStyleSheet *a_ua_sheet) ;
|
||||
|
||||
CRStyleSheet * cr_cascade_get_sheet (CRCascade *a_this,
|
||||
enum CRStyleOrigin a_origin) ;
|
||||
|
||||
enum CRStatus cr_cascade_set_sheet (CRCascade *a_this,
|
||||
CRStyleSheet *a_sheet,
|
||||
enum CRStyleOrigin a_origin) ;
|
||||
|
||||
void cr_cascade_ref (CRCascade *a_this) ;
|
||||
|
||||
void cr_cascade_unref (CRCascade *a_this) ;
|
||||
|
||||
void cr_cascade_destroy (CRCascade *a_this) ;
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /*__CR_CASCADE_H__*/
|
801
src/st/croco/cr-declaration.c
Normal file
801
src/st/croco/cr-declaration.c
Normal file
@ -0,0 +1,801 @@
|
||||
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
|
||||
|
||||
/*
|
||||
* This file is part of The Croco Library
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of version 2.1 of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*
|
||||
* Author: Dodji Seketeli.
|
||||
* See COPYRIGHTS file for copyright information.
|
||||
*/
|
||||
|
||||
|
||||
#include <string.h>
|
||||
#include "cr-declaration.h"
|
||||
#include "cr-statement.h"
|
||||
#include "cr-parser.h"
|
||||
|
||||
/**
|
||||
*@CRDeclaration:
|
||||
*
|
||||
*The definition of the #CRDeclaration class.
|
||||
*/
|
||||
|
||||
/**
|
||||
* dump:
|
||||
*@a_this: the current instance of #CRDeclaration.
|
||||
*@a_fp: the destination file pointer.
|
||||
*@a_indent: the number of indentation white char.
|
||||
*
|
||||
*Dumps (serializes) one css declaration to a file.
|
||||
*/
|
||||
static void
|
||||
dump (CRDeclaration const * a_this, FILE * a_fp, glong a_indent)
|
||||
{
|
||||
guchar *str = NULL;
|
||||
|
||||
g_return_if_fail (a_this);
|
||||
|
||||
str = (guchar *) cr_declaration_to_string (a_this, a_indent);
|
||||
if (str) {
|
||||
fprintf (a_fp, "%s", str);
|
||||
g_free (str);
|
||||
str = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_declaration_new:
|
||||
* @a_statement: the statement this declaration belongs to. can be NULL.
|
||||
*@a_property: the property string of the declaration
|
||||
*@a_value: the value expression of the declaration.
|
||||
*Constructor of #CRDeclaration.
|
||||
*
|
||||
*Returns the newly built instance of #CRDeclaration, or NULL in
|
||||
*case of error.
|
||||
*
|
||||
*The returned CRDeclaration takes ownership of @a_property and @a_value.
|
||||
*(E.g. cr_declaration_destroy on this CRDeclaration will also free
|
||||
*@a_property and @a_value.)
|
||||
*/
|
||||
CRDeclaration *
|
||||
cr_declaration_new (CRStatement * a_statement,
|
||||
CRString * a_property, CRTerm * a_value)
|
||||
{
|
||||
CRDeclaration *result = NULL;
|
||||
|
||||
g_return_val_if_fail (a_property, NULL);
|
||||
|
||||
if (a_statement)
|
||||
g_return_val_if_fail (a_statement
|
||||
&& ((a_statement->type == RULESET_STMT)
|
||||
|| (a_statement->type
|
||||
== AT_FONT_FACE_RULE_STMT)
|
||||
|| (a_statement->type
|
||||
== AT_PAGE_RULE_STMT)), NULL);
|
||||
|
||||
result = g_try_malloc (sizeof (CRDeclaration));
|
||||
if (!result) {
|
||||
cr_utils_trace_info ("Out of memory");
|
||||
return NULL;
|
||||
}
|
||||
memset (result, 0, sizeof (CRDeclaration));
|
||||
result->property = a_property;
|
||||
result->value = a_value;
|
||||
|
||||
if (a_value) {
|
||||
cr_term_ref (a_value);
|
||||
}
|
||||
result->parent_statement = a_statement;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_declaration_parse_from_buf:
|
||||
*@a_statement: the parent css2 statement of this
|
||||
*this declaration. Must be non NULL and of type
|
||||
*RULESET_STMT (must be a ruleset).
|
||||
*@a_str: the string that contains the statement.
|
||||
*@a_enc: the encoding of a_str.
|
||||
*
|
||||
*Parses a text buffer that contains
|
||||
*a css declaration.
|
||||
*Returns the parsed declaration, or NULL in case of error.
|
||||
*/
|
||||
CRDeclaration *
|
||||
cr_declaration_parse_from_buf (CRStatement * a_statement,
|
||||
const guchar * a_str, enum CREncoding a_enc)
|
||||
{
|
||||
enum CRStatus status = CR_OK;
|
||||
CRTerm *value = NULL;
|
||||
CRString *property = NULL;
|
||||
CRDeclaration *result = NULL;
|
||||
CRParser *parser = NULL;
|
||||
gboolean important = FALSE;
|
||||
|
||||
g_return_val_if_fail (a_str, NULL);
|
||||
if (a_statement)
|
||||
g_return_val_if_fail (a_statement->type == RULESET_STMT,
|
||||
NULL);
|
||||
|
||||
parser = cr_parser_new_from_buf ((guchar*)a_str, strlen ((const char *) a_str), a_enc, FALSE);
|
||||
g_return_val_if_fail (parser, NULL);
|
||||
|
||||
status = cr_parser_try_to_skip_spaces_and_comments (parser);
|
||||
if (status != CR_OK)
|
||||
goto cleanup;
|
||||
|
||||
status = cr_parser_parse_declaration (parser, &property,
|
||||
&value, &important);
|
||||
if (status != CR_OK || !property)
|
||||
goto cleanup;
|
||||
|
||||
result = cr_declaration_new (a_statement, property, value);
|
||||
if (result) {
|
||||
property = NULL;
|
||||
value = NULL;
|
||||
result->important = important;
|
||||
}
|
||||
|
||||
cleanup:
|
||||
|
||||
if (parser) {
|
||||
cr_parser_destroy (parser);
|
||||
parser = NULL;
|
||||
}
|
||||
|
||||
if (property) {
|
||||
cr_string_destroy (property);
|
||||
property = NULL;
|
||||
}
|
||||
|
||||
if (value) {
|
||||
cr_term_destroy (value);
|
||||
value = NULL;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_declaration_parse_list_from_buf:
|
||||
*@a_str: the input buffer that contains the list of declaration to
|
||||
*parse.
|
||||
*@a_enc: the encoding of a_str
|
||||
*
|
||||
*Parses a ';' separated list of properties declaration.
|
||||
*Returns the parsed list of declaration, NULL if parsing failed.
|
||||
*/
|
||||
CRDeclaration *
|
||||
cr_declaration_parse_list_from_buf (const guchar * a_str,
|
||||
enum CREncoding a_enc)
|
||||
{
|
||||
|
||||
enum CRStatus status = CR_OK;
|
||||
CRTerm *value = NULL;
|
||||
CRString *property = NULL;
|
||||
CRDeclaration *result = NULL,
|
||||
*cur_decl = NULL;
|
||||
CRParser *parser = NULL;
|
||||
CRTknzr *tokenizer = NULL;
|
||||
gboolean important = FALSE;
|
||||
|
||||
g_return_val_if_fail (a_str, NULL);
|
||||
|
||||
parser = cr_parser_new_from_buf ((guchar*)a_str, strlen ((const char *) a_str), a_enc, FALSE);
|
||||
g_return_val_if_fail (parser, NULL);
|
||||
status = cr_parser_get_tknzr (parser, &tokenizer);
|
||||
if (status != CR_OK || !tokenizer) {
|
||||
if (status == CR_OK)
|
||||
status = CR_ERROR;
|
||||
goto cleanup;
|
||||
}
|
||||
status = cr_parser_try_to_skip_spaces_and_comments (parser);
|
||||
if (status != CR_OK)
|
||||
goto cleanup;
|
||||
|
||||
status = cr_parser_parse_declaration (parser, &property,
|
||||
&value, &important);
|
||||
if (status != CR_OK || !property) {
|
||||
if (status != CR_OK)
|
||||
status = CR_ERROR;
|
||||
goto cleanup;
|
||||
}
|
||||
result = cr_declaration_new (NULL, property, value);
|
||||
if (result) {
|
||||
property = NULL;
|
||||
value = NULL;
|
||||
result->important = important;
|
||||
}
|
||||
/*now, go parse the other declarations */
|
||||
for (;;) {
|
||||
guint32 c = 0;
|
||||
|
||||
cr_parser_try_to_skip_spaces_and_comments (parser);
|
||||
status = cr_tknzr_peek_char (tokenizer, &c);
|
||||
if (status != CR_OK) {
|
||||
if (status == CR_END_OF_INPUT_ERROR)
|
||||
status = CR_OK;
|
||||
goto cleanup;
|
||||
}
|
||||
if (c == ';') {
|
||||
status = cr_tknzr_read_char (tokenizer, &c);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
important = FALSE;
|
||||
cr_parser_try_to_skip_spaces_and_comments (parser);
|
||||
status = cr_parser_parse_declaration (parser, &property,
|
||||
&value, &important);
|
||||
if (status != CR_OK || !property) {
|
||||
if (status == CR_END_OF_INPUT_ERROR) {
|
||||
status = CR_OK;
|
||||
}
|
||||
break;
|
||||
}
|
||||
cur_decl = cr_declaration_new (NULL, property, value);
|
||||
if (cur_decl) {
|
||||
cur_decl->important = important;
|
||||
result = cr_declaration_append (result, cur_decl);
|
||||
property = NULL;
|
||||
value = NULL;
|
||||
cur_decl = NULL;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
cleanup:
|
||||
|
||||
if (parser) {
|
||||
cr_parser_destroy (parser);
|
||||
parser = NULL;
|
||||
}
|
||||
|
||||
if (property) {
|
||||
cr_string_destroy (property);
|
||||
property = NULL;
|
||||
}
|
||||
|
||||
if (value) {
|
||||
cr_term_destroy (value);
|
||||
value = NULL;
|
||||
}
|
||||
|
||||
if (status != CR_OK && result) {
|
||||
cr_declaration_destroy (result);
|
||||
result = NULL;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_declaration_append:
|
||||
*@a_this: the current declaration list.
|
||||
*@a_new: the declaration to append.
|
||||
*
|
||||
*Appends a new declaration to the current declarations list.
|
||||
*Returns the declaration list with a_new appended to it, or NULL
|
||||
*in case of error.
|
||||
*/
|
||||
CRDeclaration *
|
||||
cr_declaration_append (CRDeclaration * a_this, CRDeclaration * a_new)
|
||||
{
|
||||
CRDeclaration *cur = NULL;
|
||||
|
||||
g_return_val_if_fail (a_new, NULL);
|
||||
|
||||
if (!a_this)
|
||||
return a_new;
|
||||
|
||||
for (cur = a_this; cur && cur->next; cur = cur->next) ;
|
||||
|
||||
cur->next = a_new;
|
||||
a_new->prev = cur;
|
||||
|
||||
return a_this;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_declaration_unlink:
|
||||
*@a_decls: the declaration to unlink.
|
||||
*
|
||||
*Unlinks the declaration from the declaration list.
|
||||
*case of a successfull completion, NULL otherwise.
|
||||
*
|
||||
*Returns a pointer to the unlinked declaration in
|
||||
*/
|
||||
CRDeclaration *
|
||||
cr_declaration_unlink (CRDeclaration * a_decl)
|
||||
{
|
||||
CRDeclaration *result = a_decl;
|
||||
|
||||
g_return_val_if_fail (result, NULL);
|
||||
|
||||
/*
|
||||
*some sanity checks first
|
||||
*/
|
||||
if (a_decl->prev) {
|
||||
g_return_val_if_fail (a_decl->prev->next == a_decl, NULL);
|
||||
|
||||
}
|
||||
if (a_decl->next) {
|
||||
g_return_val_if_fail (a_decl->next->prev == a_decl, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
*now, the real unlinking job.
|
||||
*/
|
||||
if (a_decl->prev) {
|
||||
a_decl->prev->next = a_decl->next;
|
||||
}
|
||||
if (a_decl->next) {
|
||||
a_decl->next->prev = a_decl->prev;
|
||||
}
|
||||
if (a_decl->parent_statement) {
|
||||
CRDeclaration **children_decl_ptr = NULL;
|
||||
|
||||
switch (a_decl->parent_statement->type) {
|
||||
case RULESET_STMT:
|
||||
if (a_decl->parent_statement->kind.ruleset) {
|
||||
children_decl_ptr =
|
||||
&a_decl->parent_statement->
|
||||
kind.ruleset->decl_list;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case AT_FONT_FACE_RULE_STMT:
|
||||
if (a_decl->parent_statement->kind.font_face_rule) {
|
||||
children_decl_ptr =
|
||||
&a_decl->parent_statement->
|
||||
kind.font_face_rule->decl_list;
|
||||
}
|
||||
break;
|
||||
case AT_PAGE_RULE_STMT:
|
||||
if (a_decl->parent_statement->kind.page_rule) {
|
||||
children_decl_ptr =
|
||||
&a_decl->parent_statement->
|
||||
kind.page_rule->decl_list;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (children_decl_ptr
|
||||
&& *children_decl_ptr && *children_decl_ptr == a_decl)
|
||||
*children_decl_ptr = (*children_decl_ptr)->next;
|
||||
}
|
||||
|
||||
a_decl->next = NULL;
|
||||
a_decl->prev = NULL;
|
||||
a_decl->parent_statement = NULL;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_declaration_prepend:
|
||||
* @a_this: the current declaration list.
|
||||
* @a_new: the declaration to prepend.
|
||||
*
|
||||
* prepends a declaration to the current declaration list.
|
||||
*
|
||||
* Returns the list with a_new prepended or NULL in case of error.
|
||||
*/
|
||||
CRDeclaration *
|
||||
cr_declaration_prepend (CRDeclaration * a_this, CRDeclaration * a_new)
|
||||
{
|
||||
CRDeclaration *cur = NULL;
|
||||
|
||||
g_return_val_if_fail (a_new, NULL);
|
||||
|
||||
if (!a_this)
|
||||
return a_new;
|
||||
|
||||
a_this->prev = a_new;
|
||||
a_new->next = a_this;
|
||||
|
||||
for (cur = a_new; cur && cur->prev; cur = cur->prev) ;
|
||||
|
||||
return cur;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_declaration_append2:
|
||||
*@a_this: the current declaration list.
|
||||
*@a_prop: the property string of the declaration to append.
|
||||
*@a_value: the value of the declaration to append.
|
||||
*
|
||||
*Appends a declaration to the current declaration list.
|
||||
*Returns the list with the new property appended to it, or NULL in
|
||||
*case of an error.
|
||||
*/
|
||||
CRDeclaration *
|
||||
cr_declaration_append2 (CRDeclaration * a_this,
|
||||
CRString * a_prop, CRTerm * a_value)
|
||||
{
|
||||
CRDeclaration *new_elem = NULL;
|
||||
|
||||
if (a_this) {
|
||||
new_elem = cr_declaration_new (a_this->parent_statement,
|
||||
a_prop, a_value);
|
||||
} else {
|
||||
new_elem = cr_declaration_new (NULL, a_prop, a_value);
|
||||
}
|
||||
|
||||
g_return_val_if_fail (new_elem, NULL);
|
||||
|
||||
return cr_declaration_append (a_this, new_elem);
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_declaration_dump:
|
||||
*@a_this: the current instance of #CRDeclaration.
|
||||
*@a_fp: the destination file.
|
||||
*@a_indent: the number of indentation white char.
|
||||
*@a_one_per_line: whether to put one declaration per line of not .
|
||||
*
|
||||
*
|
||||
*Dumps a declaration list to a file.
|
||||
*/
|
||||
void
|
||||
cr_declaration_dump (CRDeclaration const * a_this, FILE * a_fp, glong a_indent,
|
||||
gboolean a_one_per_line)
|
||||
{
|
||||
CRDeclaration const *cur = NULL;
|
||||
|
||||
g_return_if_fail (a_this);
|
||||
|
||||
for (cur = a_this; cur; cur = cur->next) {
|
||||
if (cur->prev) {
|
||||
if (a_one_per_line == TRUE)
|
||||
fprintf (a_fp, ";\n");
|
||||
else
|
||||
fprintf (a_fp, "; ");
|
||||
}
|
||||
dump (cur, a_fp, a_indent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_declaration_dump_one:
|
||||
*@a_this: the current instance of #CRDeclaration.
|
||||
*@a_fp: the destination file.
|
||||
*@a_indent: the number of indentation white char.
|
||||
*
|
||||
*Dumps the first declaration of the declaration list to a file.
|
||||
*/
|
||||
void
|
||||
cr_declaration_dump_one (CRDeclaration const * a_this, FILE * a_fp, glong a_indent)
|
||||
{
|
||||
g_return_if_fail (a_this);
|
||||
|
||||
dump (a_this, a_fp, a_indent);
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_declaration_to_string:
|
||||
*@a_this: the current instance of #CRDeclaration.
|
||||
*@a_indent: the number of indentation white char
|
||||
*to put before the actual serialisation.
|
||||
*
|
||||
*Serializes the declaration into a string
|
||||
*Returns the serialized form the declaration. The caller must
|
||||
*free the string using g_free().
|
||||
*/
|
||||
gchar *
|
||||
cr_declaration_to_string (CRDeclaration const * a_this, gulong a_indent)
|
||||
{
|
||||
GString *stringue = NULL;
|
||||
|
||||
gchar *str = NULL,
|
||||
*result = NULL;
|
||||
|
||||
g_return_val_if_fail (a_this, NULL);
|
||||
|
||||
stringue = g_string_new (NULL);
|
||||
|
||||
if (a_this->property
|
||||
&& a_this->property->stryng
|
||||
&& a_this->property->stryng->str) {
|
||||
str = g_strndup (a_this->property->stryng->str,
|
||||
a_this->property->stryng->len);
|
||||
if (str) {
|
||||
cr_utils_dump_n_chars2 (' ', stringue,
|
||||
a_indent);
|
||||
g_string_append (stringue, str);
|
||||
g_free (str);
|
||||
str = NULL;
|
||||
} else
|
||||
goto error;
|
||||
|
||||
if (a_this->value) {
|
||||
guchar *value_str = NULL;
|
||||
|
||||
value_str = cr_term_to_string (a_this->value);
|
||||
if (value_str) {
|
||||
g_string_append_printf (stringue, " : %s",
|
||||
value_str);
|
||||
g_free (value_str);
|
||||
} else
|
||||
goto error;
|
||||
}
|
||||
if (a_this->important == TRUE) {
|
||||
g_string_append_printf (stringue, " %s",
|
||||
"!important");
|
||||
}
|
||||
}
|
||||
if (stringue && stringue->str) {
|
||||
result = stringue->str;
|
||||
g_string_free (stringue, FALSE);
|
||||
}
|
||||
return result;
|
||||
|
||||
error:
|
||||
if (stringue) {
|
||||
g_string_free (stringue, TRUE);
|
||||
stringue = NULL;
|
||||
}
|
||||
if (str) {
|
||||
g_free (str);
|
||||
str = NULL;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_declaration_list_to_string:
|
||||
*@a_this: the current instance of #CRDeclaration.
|
||||
*@a_indent: the number of indentation white char
|
||||
*to put before the actual serialisation.
|
||||
*
|
||||
*Serializes the declaration list into a string
|
||||
*/
|
||||
guchar *
|
||||
cr_declaration_list_to_string (CRDeclaration const * a_this, gulong a_indent)
|
||||
{
|
||||
CRDeclaration const *cur = NULL;
|
||||
GString *stringue = NULL;
|
||||
guchar *str = NULL,
|
||||
*result = NULL;
|
||||
|
||||
g_return_val_if_fail (a_this, NULL);
|
||||
|
||||
stringue = g_string_new (NULL);
|
||||
|
||||
for (cur = a_this; cur; cur = cur->next) {
|
||||
str = (guchar *) cr_declaration_to_string (cur, a_indent);
|
||||
if (str) {
|
||||
g_string_append_printf (stringue, "%s;", str);
|
||||
g_free (str);
|
||||
} else
|
||||
break;
|
||||
}
|
||||
if (stringue && stringue->str) {
|
||||
result = (guchar *) stringue->str;
|
||||
g_string_free (stringue, FALSE);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_declaration_list_to_string2:
|
||||
*@a_this: the current instance of #CRDeclaration.
|
||||
*@a_indent: the number of indentation white char
|
||||
*@a_one_decl_per_line: whether to output one doc per line or not.
|
||||
*to put before the actual serialisation.
|
||||
*
|
||||
*Serializes the declaration list into a string
|
||||
*Returns the serialized form the declararation.
|
||||
*/
|
||||
guchar *
|
||||
cr_declaration_list_to_string2 (CRDeclaration const * a_this,
|
||||
gulong a_indent, gboolean a_one_decl_per_line)
|
||||
{
|
||||
CRDeclaration const *cur = NULL;
|
||||
GString *stringue = NULL;
|
||||
guchar *str = NULL,
|
||||
*result = NULL;
|
||||
|
||||
g_return_val_if_fail (a_this, NULL);
|
||||
|
||||
stringue = g_string_new (NULL);
|
||||
|
||||
for (cur = a_this; cur; cur = cur->next) {
|
||||
str = (guchar *) cr_declaration_to_string (cur, a_indent);
|
||||
if (str) {
|
||||
if (a_one_decl_per_line == TRUE) {
|
||||
if (cur->next)
|
||||
g_string_append_printf (stringue,
|
||||
"%s;\n", str);
|
||||
else
|
||||
g_string_append (stringue,
|
||||
(const gchar *) str);
|
||||
} else {
|
||||
if (cur->next)
|
||||
g_string_append_printf (stringue,
|
||||
"%s;", str);
|
||||
else
|
||||
g_string_append (stringue,
|
||||
(const gchar *) str);
|
||||
}
|
||||
g_free (str);
|
||||
} else
|
||||
break;
|
||||
}
|
||||
if (stringue && stringue->str) {
|
||||
result = (guchar *) stringue->str;
|
||||
g_string_free (stringue, FALSE);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_declaration_nr_props:
|
||||
*@a_this: the current instance of #CRDeclaration.
|
||||
*Return the number of properties in the declaration
|
||||
*/
|
||||
gint
|
||||
cr_declaration_nr_props (CRDeclaration const * a_this)
|
||||
{
|
||||
CRDeclaration const *cur = NULL;
|
||||
int nr = 0;
|
||||
|
||||
g_return_val_if_fail (a_this, -1);
|
||||
|
||||
for (cur = a_this; cur; cur = cur->next)
|
||||
nr++;
|
||||
return nr;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_declaration_get_from_list:
|
||||
*@a_this: the current instance of #CRDeclaration.
|
||||
*@itemnr: the index into the declaration list.
|
||||
*
|
||||
*Use an index to get a CRDeclaration from the declaration list.
|
||||
*
|
||||
*Returns #CRDeclaration at position itemnr,
|
||||
*if itemnr > number of declarations - 1,
|
||||
*it will return NULL.
|
||||
*/
|
||||
CRDeclaration *
|
||||
cr_declaration_get_from_list (CRDeclaration * a_this, int itemnr)
|
||||
{
|
||||
CRDeclaration *cur = NULL;
|
||||
int nr = 0;
|
||||
|
||||
g_return_val_if_fail (a_this, NULL);
|
||||
|
||||
for (cur = a_this; cur; cur = cur->next)
|
||||
if (nr++ == itemnr)
|
||||
return cur;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_declaration_get_by_prop_name:
|
||||
*@a_this: the current instance of #CRDeclaration.
|
||||
*@a_prop: the property name to search for.
|
||||
*
|
||||
*Use property name to get a CRDeclaration from the declaration list.
|
||||
*Returns #CRDeclaration with property name a_prop, or NULL if not found.
|
||||
*/
|
||||
CRDeclaration *
|
||||
cr_declaration_get_by_prop_name (CRDeclaration * a_this,
|
||||
const guchar * a_prop)
|
||||
{
|
||||
CRDeclaration *cur = NULL;
|
||||
|
||||
g_return_val_if_fail (a_this, NULL);
|
||||
g_return_val_if_fail (a_prop, NULL);
|
||||
|
||||
for (cur = a_this; cur; cur = cur->next) {
|
||||
if (cur->property
|
||||
&& cur->property->stryng
|
||||
&& cur->property->stryng->str) {
|
||||
if (!strcmp (cur->property->stryng->str,
|
||||
(const char *) a_prop)) {
|
||||
return cur;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_declaration_ref:
|
||||
*@a_this: the current instance of #CRDeclaration.
|
||||
*
|
||||
*Increases the ref count of the current instance of #CRDeclaration.
|
||||
*/
|
||||
void
|
||||
cr_declaration_ref (CRDeclaration * a_this)
|
||||
{
|
||||
g_return_if_fail (a_this);
|
||||
|
||||
a_this->ref_count++;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_declaration_unref:
|
||||
*@a_this: the current instance of #CRDeclaration.
|
||||
*
|
||||
*Decrements the ref count of the current instance of #CRDeclaration.
|
||||
*If the ref count reaches zero, the current instance of #CRDeclaration
|
||||
*if destroyed.
|
||||
*Returns TRUE if @a_this was destroyed (ref count reached zero),
|
||||
*FALSE otherwise.
|
||||
*/
|
||||
gboolean
|
||||
cr_declaration_unref (CRDeclaration * a_this)
|
||||
{
|
||||
g_return_val_if_fail (a_this, FALSE);
|
||||
|
||||
if (a_this->ref_count) {
|
||||
a_this->ref_count--;
|
||||
}
|
||||
|
||||
if (a_this->ref_count == 0) {
|
||||
cr_declaration_destroy (a_this);
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_declaration_destroy:
|
||||
*@a_this: the current instance of #CRDeclaration.
|
||||
*
|
||||
*Destructor of the declaration list.
|
||||
*/
|
||||
void
|
||||
cr_declaration_destroy (CRDeclaration * a_this)
|
||||
{
|
||||
CRDeclaration *cur = NULL;
|
||||
|
||||
g_return_if_fail (a_this);
|
||||
|
||||
/*
|
||||
* Go to the last element of the list.
|
||||
*/
|
||||
for (cur = a_this; cur->next; cur = cur->next)
|
||||
g_assert (cur->next->prev == cur);
|
||||
|
||||
/*
|
||||
* Walk backward the list and free each "next" element.
|
||||
* Meanwhile, free each property/value pair contained in the list.
|
||||
*/
|
||||
for (; cur; cur = cur->prev) {
|
||||
g_free (cur->next);
|
||||
cur->next = NULL;
|
||||
|
||||
if (cur->property) {
|
||||
cr_string_destroy (cur->property);
|
||||
cur->property = NULL;
|
||||
}
|
||||
|
||||
if (cur->value) {
|
||||
cr_term_destroy (cur->value);
|
||||
cur->value = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
g_free (a_this);
|
||||
}
|
136
src/st/croco/cr-declaration.h
Normal file
136
src/st/croco/cr-declaration.h
Normal file
@ -0,0 +1,136 @@
|
||||
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
|
||||
|
||||
/*
|
||||
* This file is part of The Croco Library
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of version 2.1 of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*
|
||||
* See the COPYRIGHTS file for copyright information.
|
||||
*/
|
||||
|
||||
#ifndef __CR_DECLARATION_H__
|
||||
#define __CR_DECLARATION_H__
|
||||
|
||||
#include <stdio.h>
|
||||
#include "cr-utils.h"
|
||||
#include "cr-term.h"
|
||||
#include "cr-parsing-location.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/**
|
||||
*@file
|
||||
*The declaration of the #CRDeclaration class.
|
||||
*/
|
||||
|
||||
/*forward declaration of what is defined in cr-statement.h*/
|
||||
typedef struct _CRStatement CRStatement ;
|
||||
|
||||
/**
|
||||
*The abstraction of a css declaration defined by the
|
||||
*css2 spec in chapter 4.
|
||||
*It is actually a chained list of property/value pairs.
|
||||
*/
|
||||
typedef struct _CRDeclaration CRDeclaration ;
|
||||
struct _CRDeclaration
|
||||
{
|
||||
/**The property.*/
|
||||
CRString *property ;
|
||||
|
||||
/**The value of the property.*/
|
||||
CRTerm *value ;
|
||||
|
||||
/*the ruleset that contains this declaration*/
|
||||
CRStatement *parent_statement ;
|
||||
|
||||
/*the next declaration*/
|
||||
CRDeclaration *next ;
|
||||
|
||||
/*the previous one declaration*/
|
||||
CRDeclaration *prev ;
|
||||
|
||||
/*does the declaration have the important keyword ?*/
|
||||
gboolean important ;
|
||||
|
||||
glong ref_count ;
|
||||
|
||||
CRParsingLocation location ;
|
||||
/*reserved for future usage*/
|
||||
gpointer rfu0 ;
|
||||
gpointer rfu1 ;
|
||||
gpointer rfu2 ;
|
||||
gpointer rfu3 ;
|
||||
} ;
|
||||
|
||||
|
||||
CRDeclaration * cr_declaration_new (CRStatement *a_statement,
|
||||
CRString *a_property,
|
||||
CRTerm *a_value) ;
|
||||
|
||||
|
||||
CRDeclaration * cr_declaration_parse_from_buf (CRStatement *a_statement,
|
||||
const guchar *a_str,
|
||||
enum CREncoding a_enc) ;
|
||||
|
||||
CRDeclaration * cr_declaration_parse_list_from_buf (const guchar *a_str,
|
||||
enum CREncoding a_enc) ;
|
||||
|
||||
CRDeclaration * cr_declaration_append (CRDeclaration *a_this,
|
||||
CRDeclaration *a_new) ;
|
||||
|
||||
CRDeclaration * cr_declaration_append2 (CRDeclaration *a_this,
|
||||
CRString *a_prop,
|
||||
CRTerm *a_value) ;
|
||||
|
||||
CRDeclaration * cr_declaration_prepend (CRDeclaration *a_this,
|
||||
CRDeclaration *a_new) ;
|
||||
|
||||
CRDeclaration * cr_declaration_unlink (CRDeclaration * a_decl) ;
|
||||
|
||||
void
|
||||
cr_declaration_dump (CRDeclaration const *a_this,
|
||||
FILE *a_fp, glong a_indent,
|
||||
gboolean a_one_per_line) ;
|
||||
|
||||
void cr_declaration_dump_one (CRDeclaration const *a_this,
|
||||
FILE *a_fp, glong a_indent) ;
|
||||
|
||||
gint cr_declaration_nr_props (CRDeclaration const *a_this) ;
|
||||
|
||||
CRDeclaration * cr_declaration_get_from_list (CRDeclaration *a_this,
|
||||
int itemnr) ;
|
||||
|
||||
CRDeclaration * cr_declaration_get_by_prop_name (CRDeclaration *a_this,
|
||||
const guchar *a_str) ;
|
||||
|
||||
gchar * cr_declaration_to_string (CRDeclaration const *a_this,
|
||||
gulong a_indent) ;
|
||||
|
||||
guchar * cr_declaration_list_to_string (CRDeclaration const *a_this,
|
||||
gulong a_indent) ;
|
||||
|
||||
guchar * cr_declaration_list_to_string2 (CRDeclaration const *a_this,
|
||||
gulong a_indent,
|
||||
gboolean a_one_decl_per_line) ;
|
||||
|
||||
void cr_declaration_ref (CRDeclaration *a_this) ;
|
||||
|
||||
gboolean cr_declaration_unref (CRDeclaration *a_this) ;
|
||||
|
||||
void cr_declaration_destroy (CRDeclaration *a_this) ;
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /*__CR_DECLARATION_H__*/
|
276
src/st/croco/cr-doc-handler.c
Normal file
276
src/st/croco/cr-doc-handler.c
Normal file
@ -0,0 +1,276 @@
|
||||
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
|
||||
|
||||
/*
|
||||
* This file is part of The Croco Library
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of version 2.1 of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*
|
||||
* See COPRYRIGHTS file for copyright information.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "cr-doc-handler.h"
|
||||
#include "cr-parser.h"
|
||||
|
||||
/**
|
||||
*@CRDocHandler:
|
||||
*
|
||||
*The definition of the CRDocHandler class.
|
||||
*Contains methods to instantiate, destroy,
|
||||
*and initialyze instances of #CRDocHandler
|
||||
*to custom values.
|
||||
*/
|
||||
|
||||
#define PRIVATE(obj) (obj)->priv
|
||||
|
||||
struct _CRDocHandlerPriv {
|
||||
/**
|
||||
*This pointer is to hold an application parsing context.
|
||||
*For example, it used by the Object Model parser to
|
||||
*store it parsing context. #CRParser does not touch it, but
|
||||
*#CROMParser does. #CROMParser allocates this pointer at
|
||||
*the beginning of the css document, and frees it at the end
|
||||
*of the document.
|
||||
*/
|
||||
gpointer context;
|
||||
|
||||
/**
|
||||
*The place where #CROMParser puts the result of its parsing, if
|
||||
*any.
|
||||
*/
|
||||
gpointer result;
|
||||
/**
|
||||
*a pointer to the parser used to parse
|
||||
*the current document.
|
||||
*/
|
||||
CRParser *parser ;
|
||||
};
|
||||
|
||||
/**
|
||||
* cr_doc_handler_new:
|
||||
*Constructor of #CRDocHandler.
|
||||
*
|
||||
*Returns the newly built instance of
|
||||
*#CRDocHandler
|
||||
*
|
||||
*/
|
||||
CRDocHandler *
|
||||
cr_doc_handler_new (void)
|
||||
{
|
||||
CRDocHandler *result = NULL;
|
||||
|
||||
result = g_try_malloc (sizeof (CRDocHandler));
|
||||
|
||||
g_return_val_if_fail (result, NULL);
|
||||
|
||||
memset (result, 0, sizeof (CRDocHandler));
|
||||
result->ref_count++;
|
||||
|
||||
result->priv = g_try_malloc (sizeof (CRDocHandlerPriv));
|
||||
if (!result->priv) {
|
||||
cr_utils_trace_info ("Out of memory exception");
|
||||
g_free (result);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cr_doc_handler_set_default_sac_handler (result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_doc_handler_get_ctxt:
|
||||
*@a_this: the current instance of #CRDocHandler.
|
||||
*@a_ctxt: out parameter. The new parsing context.
|
||||
*
|
||||
*Gets the private parsing context associated to the document handler
|
||||
*The private parsing context is used by libcroco only.
|
||||
*
|
||||
*Returns CR_OK upon successfull completion, an error code otherwise.
|
||||
*/
|
||||
enum CRStatus
|
||||
cr_doc_handler_get_ctxt (CRDocHandler const * a_this, gpointer * a_ctxt)
|
||||
{
|
||||
g_return_val_if_fail (a_this && a_this->priv, CR_BAD_PARAM_ERROR);
|
||||
|
||||
*a_ctxt = a_this->priv->context;
|
||||
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_doc_handler_set_ctxt:
|
||||
*@a_this: the current instance of #CRDocHandler
|
||||
*@a_ctxt: a pointer to the parsing context.
|
||||
*
|
||||
*Sets the private parsing context.
|
||||
*This is used by libcroco only.
|
||||
*Returns CR_OK upon successfull completion, an error code otherwise.
|
||||
*/
|
||||
enum CRStatus
|
||||
cr_doc_handler_set_ctxt (CRDocHandler * a_this, gpointer a_ctxt)
|
||||
{
|
||||
g_return_val_if_fail (a_this && a_this->priv, CR_BAD_PARAM_ERROR);
|
||||
a_this->priv->context = a_ctxt;
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_doc_handler_get_result:
|
||||
*@a_this: the current instance of #CRDocHandler
|
||||
*@a_result: out parameter. The returned result.
|
||||
*
|
||||
*Gets the private parsing result.
|
||||
*The private parsing result is used by libcroco only.
|
||||
*
|
||||
*Returns CR_OK upon successfull completion, an error code otherwise.
|
||||
*/
|
||||
enum CRStatus
|
||||
cr_doc_handler_get_result (CRDocHandler const * a_this, gpointer * a_result)
|
||||
{
|
||||
g_return_val_if_fail (a_this && a_this->priv, CR_BAD_PARAM_ERROR);
|
||||
|
||||
*a_result = a_this->priv->result;
|
||||
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_doc_handler_set_result:
|
||||
*@a_this: the current instance of #CRDocHandler
|
||||
*@a_result: the new result.
|
||||
*
|
||||
*Sets the private parsing context.
|
||||
*This is used by libcroco only.
|
||||
*
|
||||
*Returns CR_OK upon successfull completion, an error code otherwise.
|
||||
*/
|
||||
enum CRStatus
|
||||
cr_doc_handler_set_result (CRDocHandler * a_this, gpointer a_result)
|
||||
{
|
||||
g_return_val_if_fail (a_this && a_this->priv, CR_BAD_PARAM_ERROR);
|
||||
a_this->priv->result = a_result;
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
*cr_doc_handler_set_default_sac_handler:
|
||||
*@a_this: a pointer to the current instance of #CRDocHandler.
|
||||
*
|
||||
*Sets the sac handlers contained in the current
|
||||
*instance of DocHandler to the default handlers.
|
||||
*For the time being the default handlers are
|
||||
*test handlers. This is expected to change in a
|
||||
*near future, when the libcroco gets a bit debugged.
|
||||
*
|
||||
*Returns CR_OK upon successfull completion, an error code otherwise.
|
||||
*/
|
||||
enum CRStatus
|
||||
cr_doc_handler_set_default_sac_handler (CRDocHandler * a_this)
|
||||
{
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
|
||||
|
||||
a_this->start_document = NULL;
|
||||
a_this->end_document = NULL;
|
||||
a_this->import_style = NULL;
|
||||
a_this->namespace_declaration = NULL;
|
||||
a_this->comment = NULL;
|
||||
a_this->start_selector = NULL;
|
||||
a_this->end_selector = NULL;
|
||||
a_this->property = NULL;
|
||||
a_this->start_font_face = NULL;
|
||||
a_this->end_font_face = NULL;
|
||||
a_this->start_media = NULL;
|
||||
a_this->end_media = NULL;
|
||||
a_this->start_page = NULL;
|
||||
a_this->end_page = NULL;
|
||||
a_this->ignorable_at_rule = NULL;
|
||||
a_this->error = NULL;
|
||||
a_this->unrecoverable_error = NULL;
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_doc_handler_ref:
|
||||
*@a_this: the current instance of #CRDocHandler.
|
||||
*/
|
||||
void
|
||||
cr_doc_handler_ref (CRDocHandler * a_this)
|
||||
{
|
||||
g_return_if_fail (a_this);
|
||||
|
||||
a_this->ref_count++;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_doc_handler_unref:
|
||||
*@a_this: the currrent instance of #CRDocHandler.
|
||||
*
|
||||
*Decreases the ref count of the current instance of #CRDocHandler.
|
||||
*If the ref count reaches '0' then, destroys the instance.
|
||||
*
|
||||
*Returns TRUE if the instance as been destroyed, FALSE otherwise.
|
||||
*/
|
||||
gboolean
|
||||
cr_doc_handler_unref (CRDocHandler * a_this)
|
||||
{
|
||||
g_return_val_if_fail (a_this, FALSE);
|
||||
|
||||
if (a_this->ref_count > 0) {
|
||||
a_this->ref_count--;
|
||||
}
|
||||
|
||||
if (a_this->ref_count == 0) {
|
||||
cr_doc_handler_destroy (a_this);
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE ;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_doc_handler_destroy:
|
||||
*@a_this: the instance of #CRDocHandler to
|
||||
*destroy.
|
||||
*
|
||||
*The destructor of the #CRDocHandler class.
|
||||
*/
|
||||
void
|
||||
cr_doc_handler_destroy (CRDocHandler * a_this)
|
||||
{
|
||||
g_return_if_fail (a_this);
|
||||
|
||||
if (a_this->priv) {
|
||||
g_free (a_this->priv);
|
||||
a_this->priv = NULL;
|
||||
}
|
||||
g_free (a_this);
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_doc_handler_associate_a_parser:
|
||||
*Associates a parser to the current document handler
|
||||
*
|
||||
*@a_this: the current instance of document handler.
|
||||
*@a_parser: the parser to associate.
|
||||
*/
|
||||
void
|
||||
cr_doc_handler_associate_a_parser (CRDocHandler *a_this,
|
||||
gpointer a_parser)
|
||||
{
|
||||
g_return_if_fail (a_this && PRIVATE (a_this)
|
||||
&& a_parser) ;
|
||||
|
||||
PRIVATE (a_this)->parser = a_parser ;
|
||||
}
|
298
src/st/croco/cr-doc-handler.h
Normal file
298
src/st/croco/cr-doc-handler.h
Normal file
@ -0,0 +1,298 @@
|
||||
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
|
||||
|
||||
/*
|
||||
* This file is part of The Croco Library
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of version 2.1 of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*
|
||||
* See the COPYRIGHTS file for copyright information.
|
||||
*/
|
||||
|
||||
#ifndef __CR_DOC_HANDLER_H__
|
||||
#define __CR_DOC_HANDLER_H__
|
||||
|
||||
/**
|
||||
*@file
|
||||
*The declaration of the #CRDocumentHandler class.
|
||||
*This class is actually the parsing events handler.
|
||||
*/
|
||||
|
||||
#include <glib.h>
|
||||
#include "cr-utils.h"
|
||||
#include "cr-input.h"
|
||||
#include "cr-stylesheet.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
||||
typedef struct _CRDocHandler CRDocHandler ;
|
||||
|
||||
struct _CRDocHandlerPriv ;
|
||||
typedef struct _CRDocHandlerPriv CRDocHandlerPriv ;
|
||||
|
||||
|
||||
/**
|
||||
*The SAC document handler.
|
||||
*An instance of this class is to
|
||||
*be passed to a parser. Then, during the parsing
|
||||
*the parser calls the convenient function pointer
|
||||
*whenever a particular event (a css construction) occurs.
|
||||
*/
|
||||
struct _CRDocHandler
|
||||
{
|
||||
CRDocHandlerPriv *priv ;
|
||||
|
||||
/**
|
||||
*This pointer is to be used by the application for
|
||||
*it custom needs. It is there to extend the doc handler.
|
||||
*/
|
||||
gpointer app_data ;
|
||||
|
||||
/**
|
||||
*Is called at the beginning of the parsing of the document.
|
||||
*@param a_this a pointer to the current instance of
|
||||
*#CRDocHandler.
|
||||
*/
|
||||
void (*start_document) (CRDocHandler *a_this) ;
|
||||
|
||||
/**
|
||||
*Is called to notify the end of the parsing of the document.
|
||||
*@param a_this a pointer to the current instance of
|
||||
*#CRDocHandler.
|
||||
*/
|
||||
void (*end_document) (CRDocHandler *a_this) ;
|
||||
|
||||
/**
|
||||
*Is called to notify an at charset rule.
|
||||
*@param a_this the document handler.
|
||||
*@param a_charset the declared charset.
|
||||
*/
|
||||
void (*charset) (CRDocHandler *a_this,
|
||||
CRString *a_charset,
|
||||
CRParsingLocation *a_charset_sym_location) ;
|
||||
|
||||
/**
|
||||
*Is called to notify an import statement in
|
||||
*the stylesheet.
|
||||
*@param a_this the current instance of #CRDocHandler.
|
||||
*@param a_media_list a doubly linked list of GString objects.
|
||||
*Each GString object contains a string which is the
|
||||
*destination media for style information.
|
||||
*@param a_uri the uri of the imported style sheet.
|
||||
*@param a_uri_default_ns the default namespace of URI
|
||||
*@param a_location the parsing location of the '\@import'
|
||||
*keyword.
|
||||
*of the imported style sheet.
|
||||
*/
|
||||
void (*import_style) (CRDocHandler *a_this,
|
||||
GList *a_media_list,
|
||||
CRString *a_uri,
|
||||
CRString *a_uri_default_ns,
|
||||
CRParsingLocation *a_location) ;
|
||||
|
||||
void (*import_style_result) (CRDocHandler *a_this,
|
||||
GList *a_media_list,
|
||||
CRString *a_uri,
|
||||
CRString *a_uri_default_ns,
|
||||
CRStyleSheet *a_sheet) ;
|
||||
|
||||
/**
|
||||
*Is called to notify a namespace declaration.
|
||||
*Not used yet.
|
||||
*@param a_this the current instance of #CRDocHandler.
|
||||
*@param a_prefix the prefix of the namespace.
|
||||
*@param a_uri the uri of the namespace.
|
||||
*@param a_location the location of the "@namespace" keyword.
|
||||
*/
|
||||
void (*namespace_declaration) (CRDocHandler *a_this,
|
||||
CRString *a_prefix,
|
||||
CRString *a_uri,
|
||||
CRParsingLocation *a_location) ;
|
||||
|
||||
/**
|
||||
*Is called to notify a comment.
|
||||
*@param a_this a pointer to the current instance
|
||||
*of #CRDocHandler.
|
||||
*@param a_comment the comment.
|
||||
*/
|
||||
void (*comment) (CRDocHandler *a_this,
|
||||
CRString *a_comment) ;
|
||||
|
||||
/**
|
||||
*Is called to notify the beginning of a rule
|
||||
*statement.
|
||||
*@param a_this the current instance of #CRDocHandler.
|
||||
*@param a_selector_list the list of selectors that precedes
|
||||
*the rule declarations.
|
||||
*/
|
||||
void (*start_selector) (CRDocHandler * a_this,
|
||||
CRSelector *a_selector_list) ;
|
||||
|
||||
/**
|
||||
*Is called to notify the end of a rule statement.
|
||||
*@param a_this the current instance of #CRDocHandler.
|
||||
*@param a_selector_list the list of selectors that precedes
|
||||
*the rule declarations. This pointer is the same as
|
||||
*the one passed to start_selector() ;
|
||||
*/
|
||||
void (*end_selector) (CRDocHandler *a_this,
|
||||
CRSelector *a_selector_list) ;
|
||||
|
||||
|
||||
/**
|
||||
*Is called to notify a declaration.
|
||||
*@param a_this a pointer to the current instance
|
||||
*of #CRDocHandler.
|
||||
*@param a_name the name of the parsed property.
|
||||
*@param a_expression a css expression that represents
|
||||
*the value of the property. A css expression is
|
||||
*actually a linked list of 'terms'. Each term can
|
||||
*be linked to other using operators.
|
||||
*
|
||||
*/
|
||||
void (*property) (CRDocHandler *a_this,
|
||||
CRString *a_name,
|
||||
CRTerm *a_expression,
|
||||
gboolean a_is_important) ;
|
||||
/**
|
||||
*Is called to notify the start of a font face statement.
|
||||
*The parser invokes this method at the beginning of every
|
||||
*font face statement in the style sheet. There will
|
||||
*be a corresponding end_font_face () event for every
|
||||
*start_font_face () event.
|
||||
*
|
||||
*@param a_this a pointer to the current instance of
|
||||
*#CRDocHandler.
|
||||
*@param a_location the parsing location of the "\@font-face"
|
||||
*keyword.
|
||||
*/
|
||||
void (*start_font_face) (CRDocHandler *a_this,
|
||||
CRParsingLocation *a_location) ;
|
||||
|
||||
/**
|
||||
*Is called to notify the end of a font face statement.
|
||||
*@param a_this a pointer to the current instance of
|
||||
*#CRDocHandler.
|
||||
*/
|
||||
void (*end_font_face) (CRDocHandler *a_this) ;
|
||||
|
||||
|
||||
/**
|
||||
*Is called to notify the beginning of a media statement.
|
||||
*The parser will invoke this method at the beginning of
|
||||
*every media statement in the style sheet. There will be
|
||||
*a corresponding end_media() event for every start_media()
|
||||
*event.
|
||||
*@param a_this a pointer to the current instance of
|
||||
*#CRDocHandler.
|
||||
*@param a_media_list a double linked list of
|
||||
#CRString * objects.
|
||||
*Each CRString objects is actually a destination media for
|
||||
*the style information.
|
||||
*/
|
||||
void (*start_media) (CRDocHandler *a_this,
|
||||
GList *a_media_list,
|
||||
CRParsingLocation *a_location) ;
|
||||
|
||||
/**
|
||||
*Is called to notify the end of a media statement.
|
||||
*@param a_this a pointer to the current instance
|
||||
*of #CRDocHandler.
|
||||
*@param a_media_list a double linked list of GString * objects.
|
||||
*Each GString objects is actually a destination media for
|
||||
*the style information.
|
||||
*/
|
||||
void (*end_media) (CRDocHandler *a_this,
|
||||
GList *a_media_list) ;
|
||||
|
||||
/**
|
||||
*Is called to notify the beginning of a page statement.
|
||||
*The parser invokes this function at the beginning of
|
||||
*every page statement in the style sheet. There will be
|
||||
*a corresponding end_page() event for every single
|
||||
*start_page() event.
|
||||
*@param a_this a pointer to the current instance of
|
||||
*#CRDocHandler.
|
||||
*@param a_name the name of the page (if any, null otherwise).
|
||||
*@param a_pseudo_page the pseudo page (if any, null otherwise).
|
||||
*@param a_location the parsing location of the "\@page" keyword.
|
||||
*/
|
||||
void (*start_page) (CRDocHandler *a_this,
|
||||
CRString *a_name,
|
||||
CRString *a_pseudo_page,
|
||||
CRParsingLocation *a_location) ;
|
||||
|
||||
/**
|
||||
*Is called to notify the end of a page statement.
|
||||
*@param a_this a pointer to the current instance of
|
||||
*#CRDocHandler.
|
||||
*@param a_name the name of the page (if any, null otherwise).
|
||||
*@param a_pseudo_page the pseudo page (if any, null otherwise).
|
||||
*/
|
||||
void (*end_page) (CRDocHandler *a_this,
|
||||
CRString *a_name,
|
||||
CRString *pseudo_page) ;
|
||||
|
||||
/**
|
||||
*Is Called to notify an unknown at-rule not supported
|
||||
*by this parser.
|
||||
*/
|
||||
void (*ignorable_at_rule) (CRDocHandler *a_this,
|
||||
CRString *a_name) ;
|
||||
|
||||
/**
|
||||
*Is called to notify a parsing error. After this error
|
||||
*the application must ignore the rule being parsed, if
|
||||
*any. After completion of this callback,
|
||||
*the parser will then try to resume the parsing,
|
||||
*ignoring the current error.
|
||||
*/
|
||||
void (*error) (CRDocHandler *a_this) ;
|
||||
|
||||
/**
|
||||
*Is called to notify an unrecoverable parsing error.
|
||||
*This is the place to put emergency routines that free allocated
|
||||
*resources.
|
||||
*/
|
||||
void (*unrecoverable_error) (CRDocHandler *a_this) ;
|
||||
|
||||
gboolean resolve_import ;
|
||||
gulong ref_count ;
|
||||
} ;
|
||||
|
||||
CRDocHandler * cr_doc_handler_new (void) ;
|
||||
|
||||
enum CRStatus cr_doc_handler_set_result (CRDocHandler *a_this, gpointer a_result) ;
|
||||
|
||||
enum CRStatus cr_doc_handler_get_result (CRDocHandler const *a_this, gpointer * a_result) ;
|
||||
|
||||
enum CRStatus cr_doc_handler_set_ctxt (CRDocHandler *a_this, gpointer a_ctxt) ;
|
||||
|
||||
enum CRStatus cr_doc_handler_get_ctxt (CRDocHandler const *a_this, gpointer * a_ctxt) ;
|
||||
|
||||
enum CRStatus cr_doc_handler_set_default_sac_handler (CRDocHandler *a_this) ;
|
||||
|
||||
void cr_doc_handler_associate_a_parser (CRDocHandler *a_this,
|
||||
gpointer a_parser) ;
|
||||
|
||||
void cr_doc_handler_ref (CRDocHandler *a_this) ;
|
||||
|
||||
gboolean cr_doc_handler_unref (CRDocHandler *a_this) ;
|
||||
|
||||
void cr_doc_handler_destroy (CRDocHandler *a_this) ;
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /*__CR_DOC_HANDLER_H__*/
|
184
src/st/croco/cr-enc-handler.c
Normal file
184
src/st/croco/cr-enc-handler.c
Normal file
@ -0,0 +1,184 @@
|
||||
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
|
||||
|
||||
/*
|
||||
* This file is part of The Croco Library
|
||||
*
|
||||
* Copyright (C) 2002-2003 Dodji Seketeli <dodji@seketeli.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of version 2.1 of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*/
|
||||
|
||||
/*
|
||||
*$Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
*@file
|
||||
*The definition of the #CREncHandler class.
|
||||
*/
|
||||
|
||||
#include "cr-enc-handler.h"
|
||||
#include "cr-utils.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
struct CREncAlias {
|
||||
const gchar *name;
|
||||
enum CREncoding encoding;
|
||||
};
|
||||
|
||||
static struct CREncAlias gv_default_aliases[] = {
|
||||
{"UTF-8", CR_UTF_8},
|
||||
{"UTF_8", CR_UTF_8},
|
||||
{"UTF8", CR_UTF_8},
|
||||
{"UTF-16", CR_UTF_16},
|
||||
{"UTF_16", CR_UTF_16},
|
||||
{"UTF16", CR_UTF_16},
|
||||
{"UCS1", CR_UCS_1},
|
||||
{"UCS-1", CR_UCS_1},
|
||||
{"UCS_1", CR_UCS_1},
|
||||
{"ISO-8859-1", CR_UCS_1},
|
||||
{"ISO_8859-1", CR_UCS_1},
|
||||
{"UCS-1", CR_UCS_1},
|
||||
{"UCS_1", CR_UCS_1},
|
||||
{"UCS4", CR_UCS_4},
|
||||
{"UCS-4", CR_UCS_4},
|
||||
{"UCS_4", CR_UCS_4},
|
||||
{"ASCII", CR_ASCII},
|
||||
{0, 0}
|
||||
};
|
||||
|
||||
static CREncHandler gv_default_enc_handlers[] = {
|
||||
{CR_UCS_1, cr_utils_ucs1_to_utf8, cr_utils_utf8_to_ucs1,
|
||||
cr_utils_ucs1_str_len_as_utf8, cr_utils_utf8_str_len_as_ucs1},
|
||||
|
||||
{CR_ISO_8859_1, cr_utils_ucs1_to_utf8, cr_utils_utf8_to_ucs1,
|
||||
cr_utils_ucs1_str_len_as_utf8, cr_utils_utf8_str_len_as_ucs1},
|
||||
|
||||
{CR_ASCII, cr_utils_ucs1_to_utf8, cr_utils_utf8_to_ucs1,
|
||||
cr_utils_ucs1_str_len_as_utf8, cr_utils_utf8_str_len_as_ucs1},
|
||||
|
||||
{0, NULL, NULL, NULL, NULL}
|
||||
};
|
||||
|
||||
/**
|
||||
* cr_enc_handler_get_instance:
|
||||
*@a_enc: the encoding of the Handler.
|
||||
*
|
||||
*Gets the instance of encoding handler.
|
||||
*This function implements a singleton pattern.
|
||||
*
|
||||
*Returns the instance of #CREncHandler.
|
||||
*/
|
||||
CREncHandler *
|
||||
cr_enc_handler_get_instance (enum CREncoding a_enc)
|
||||
{
|
||||
gulong i = 0;
|
||||
|
||||
for (i = 0; gv_default_enc_handlers[i].encoding; i++) {
|
||||
if (gv_default_enc_handlers[i].encoding == a_enc) {
|
||||
return (CREncHandler *) & gv_default_enc_handlers[i];
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_enc_handler_resolve_enc_alias:
|
||||
*@a_alias_name: the encoding name.
|
||||
*@a_enc: output param. The returned encoding type
|
||||
*or 0 if the alias is not supported.
|
||||
*
|
||||
*Given an encoding name (called an alias name)
|
||||
*the function returns the matching encoding type.
|
||||
*
|
||||
*Returns CR_OK upon successfull completion, an error code otherwise.
|
||||
*/
|
||||
enum CRStatus
|
||||
cr_enc_handler_resolve_enc_alias (const guchar * a_alias_name,
|
||||
enum CREncoding *a_enc)
|
||||
{
|
||||
gulong i = 0;
|
||||
guchar *alias_name_up = NULL;
|
||||
enum CRStatus status = CR_ENCODING_NOT_FOUND_ERROR;
|
||||
|
||||
g_return_val_if_fail (a_alias_name != NULL, CR_BAD_PARAM_ERROR);
|
||||
|
||||
alias_name_up = (guchar *) g_ascii_strup ((const gchar *) a_alias_name, -1);
|
||||
|
||||
for (i = 0; gv_default_aliases[i].name; i++) {
|
||||
if (!strcmp (gv_default_aliases[i].name, (const gchar *) alias_name_up)) {
|
||||
*a_enc = gv_default_aliases[i].encoding;
|
||||
status = CR_OK;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_enc_handler_convert_input:
|
||||
*@a_this: the current instance of #CREncHandler.
|
||||
*@a_in: the input buffer to convert.
|
||||
*@a_in_len: in/out parameter. The len of the input
|
||||
*buffer to convert. After return, contains the number of
|
||||
*bytes actually consumed.
|
||||
*@a_out: output parameter. The converted output buffer.
|
||||
*Must be freed by the buffer.
|
||||
*@a_out_len: output parameter. The length of the output buffer.
|
||||
*
|
||||
*Converts a raw input buffer into an utf8 buffer.
|
||||
*
|
||||
*Returns CR_OK upon successfull completion, an error code otherwise.
|
||||
*/
|
||||
enum CRStatus
|
||||
cr_enc_handler_convert_input (CREncHandler * a_this,
|
||||
const guchar * a_in,
|
||||
gulong * a_in_len,
|
||||
guchar ** a_out, gulong * a_out_len)
|
||||
{
|
||||
enum CRStatus status = CR_OK;
|
||||
|
||||
g_return_val_if_fail (a_this && a_in && a_in_len && a_out,
|
||||
CR_BAD_PARAM_ERROR);
|
||||
|
||||
if (a_this->decode_input == NULL)
|
||||
return CR_OK;
|
||||
|
||||
if (a_this->enc_str_len_as_utf8) {
|
||||
status = a_this->enc_str_len_as_utf8 (a_in,
|
||||
&a_in[*a_in_len - 1],
|
||||
a_out_len);
|
||||
|
||||
g_return_val_if_fail (status == CR_OK, status);
|
||||
} else {
|
||||
*a_out_len = *a_in_len;
|
||||
}
|
||||
|
||||
*a_out = g_malloc0 (*a_out_len);
|
||||
|
||||
status = a_this->decode_input (a_in, a_in_len, *a_out, a_out_len);
|
||||
|
||||
if (status != CR_OK) {
|
||||
g_free (*a_out);
|
||||
*a_out = NULL;
|
||||
}
|
||||
|
||||
g_return_val_if_fail (status == CR_OK, status);
|
||||
|
||||
return CR_OK;
|
||||
}
|
94
src/st/croco/cr-enc-handler.h
Normal file
94
src/st/croco/cr-enc-handler.h
Normal file
@ -0,0 +1,94 @@
|
||||
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
|
||||
|
||||
/*
|
||||
* This file is part of The Croco Library
|
||||
*
|
||||
* Copyright (C) 2002-2003 Dodji Seketeli <dodji@seketeli.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of version 2.1 of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*/
|
||||
|
||||
/*
|
||||
*$Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
*@file:
|
||||
*The declaration of the #CREncHandler class.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __CR_ENC_HANDLER_H__
|
||||
#define __CR_ENC_HANDLER_H__
|
||||
|
||||
#include "cr-utils.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
||||
typedef struct _CREncHandler CREncHandler ;
|
||||
|
||||
typedef enum CRStatus (*CREncInputFunc) (const guchar * a_in,
|
||||
gulong *a_in_len,
|
||||
guchar *a_out,
|
||||
gulong *a_out_len) ;
|
||||
|
||||
typedef enum CRStatus (*CREncOutputFunc) (const guchar * a_in,
|
||||
gulong *a_in_len,
|
||||
guchar *a_out,
|
||||
gulong *a_out_len) ;
|
||||
|
||||
typedef enum CRStatus (*CREncInputStrLenAsUtf8Func)
|
||||
(const guchar *a_in_start,
|
||||
const guchar *a_in_end,
|
||||
gulong *a_in_size);
|
||||
|
||||
typedef enum CRStatus (*CREncUtf8StrLenAsOutputFunc)
|
||||
(const guchar *a_in_start,
|
||||
const guchar *a_in_end,
|
||||
gulong *a_in_size) ;
|
||||
|
||||
/**
|
||||
*This class is responsible of the
|
||||
*the encoding conversions stuffs in
|
||||
*libcroco.
|
||||
*/
|
||||
|
||||
struct _CREncHandler
|
||||
{
|
||||
enum CREncoding encoding ;
|
||||
CREncInputFunc decode_input ;
|
||||
CREncInputFunc encode_output ;
|
||||
CREncInputStrLenAsUtf8Func enc_str_len_as_utf8 ;
|
||||
CREncUtf8StrLenAsOutputFunc utf8_str_len_as_enc ;
|
||||
} ;
|
||||
|
||||
CREncHandler *
|
||||
cr_enc_handler_get_instance (enum CREncoding a_enc) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_enc_handler_resolve_enc_alias (const guchar *a_alias_name,
|
||||
enum CREncoding *a_enc) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_enc_handler_convert_input (CREncHandler *a_this,
|
||||
const guchar *a_in,
|
||||
gulong *a_in_len,
|
||||
guchar **a_out,
|
||||
gulong *a_out_len) ;
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /*__CR_ENC_HANDLER_H__*/
|
949
src/st/croco/cr-fonts.c
Normal file
949
src/st/croco/cr-fonts.c
Normal file
@ -0,0 +1,949 @@
|
||||
/* -*- Mode: C; indent-tabs-mode:nil; c-basic-offset: 8-*- */
|
||||
|
||||
/*
|
||||
* This file is part of The Croco Library
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of version 2.1 of
|
||||
* the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the
|
||||
* GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*
|
||||
*See COPYRIGHTS file for copyright information
|
||||
*/
|
||||
|
||||
#include "cr-fonts.h"
|
||||
#include <string.h>
|
||||
|
||||
static enum CRStatus
|
||||
cr_font_family_to_string_real (CRFontFamily const * a_this,
|
||||
gboolean a_walk_list, GString ** a_string)
|
||||
{
|
||||
guchar const *name = NULL;
|
||||
enum CRStatus result = CR_OK;
|
||||
|
||||
if (!*a_string) {
|
||||
*a_string = g_string_new (NULL);
|
||||
g_return_val_if_fail (*a_string,
|
||||
CR_INSTANCIATION_FAILED_ERROR);
|
||||
}
|
||||
|
||||
if (!a_this) {
|
||||
g_string_append (*a_string, "NULL");
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
switch (a_this->type) {
|
||||
case FONT_FAMILY_SANS_SERIF:
|
||||
name = (guchar const *) "sans-serif";
|
||||
break;
|
||||
|
||||
case FONT_FAMILY_SERIF:
|
||||
name = (guchar const *) "sans-serif";
|
||||
break;
|
||||
|
||||
case FONT_FAMILY_CURSIVE:
|
||||
name = (guchar const *) "cursive";
|
||||
break;
|
||||
|
||||
case FONT_FAMILY_FANTASY:
|
||||
name = (guchar const *) "fantasy";
|
||||
break;
|
||||
|
||||
case FONT_FAMILY_MONOSPACE:
|
||||
name = (guchar const *) "monospace";
|
||||
break;
|
||||
|
||||
case FONT_FAMILY_NON_GENERIC:
|
||||
name = (guchar const *) a_this->name;
|
||||
break;
|
||||
|
||||
default:
|
||||
name = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
if (name) {
|
||||
if (a_this->prev) {
|
||||
g_string_append_printf (*a_string, ", %s", name);
|
||||
} else {
|
||||
g_string_append (*a_string, (const gchar *) name);
|
||||
}
|
||||
}
|
||||
if (a_walk_list == TRUE && a_this->next) {
|
||||
result = cr_font_family_to_string_real (a_this->next,
|
||||
TRUE, a_string);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static const gchar *
|
||||
cr_predefined_absolute_font_size_to_string (enum CRPredefinedAbsoluteFontSize
|
||||
a_code)
|
||||
{
|
||||
gchar const *str = NULL;
|
||||
|
||||
switch (a_code) {
|
||||
case FONT_SIZE_XX_SMALL:
|
||||
str = "xx-small";
|
||||
break;
|
||||
case FONT_SIZE_X_SMALL:
|
||||
str = "x-small";
|
||||
break;
|
||||
case FONT_SIZE_SMALL:
|
||||
str = "small";
|
||||
break;
|
||||
case FONT_SIZE_MEDIUM:
|
||||
str = "medium";
|
||||
break;
|
||||
case FONT_SIZE_LARGE:
|
||||
str = "large";
|
||||
break;
|
||||
case FONT_SIZE_X_LARGE:
|
||||
str = "x-large";
|
||||
break;
|
||||
case FONT_SIZE_XX_LARGE:
|
||||
str = "xx-large";
|
||||
break;
|
||||
default:
|
||||
str = "unknown absolute font size value";
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
static const gchar *
|
||||
cr_relative_font_size_to_string (enum CRRelativeFontSize a_code)
|
||||
{
|
||||
gchar const *str = NULL;
|
||||
|
||||
switch (a_code) {
|
||||
case FONT_SIZE_LARGER:
|
||||
str = "larger";
|
||||
break;
|
||||
case FONT_SIZE_SMALLER:
|
||||
str = "smaller";
|
||||
break;
|
||||
default:
|
||||
str = "unknown relative font size value";
|
||||
break;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_font_family_new:
|
||||
* @a_type: the type of font family to create.
|
||||
* @a_name: the name of the font family.
|
||||
*
|
||||
* create a font family.
|
||||
*
|
||||
* Returns the newly built font family.
|
||||
*/
|
||||
CRFontFamily *
|
||||
cr_font_family_new (enum CRFontFamilyType a_type, guchar * a_name)
|
||||
{
|
||||
CRFontFamily *result = NULL;
|
||||
|
||||
result = g_try_malloc (sizeof (CRFontFamily));
|
||||
|
||||
if (!result) {
|
||||
cr_utils_trace_info ("Out of memory");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset (result, 0, sizeof (CRFontFamily));
|
||||
result->type = a_type;
|
||||
|
||||
cr_font_family_set_name (result, a_name);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_font_family_to_string:
|
||||
* @a_this: the current instance of #CRFontFamily.
|
||||
* @a_walk_font_family_list: wether the serialize the entire list.
|
||||
*
|
||||
* Returns the seriliazed font family. The caller has to free it using
|
||||
* g_free().
|
||||
*/
|
||||
guchar *
|
||||
cr_font_family_to_string (CRFontFamily const * a_this,
|
||||
gboolean a_walk_font_family_list)
|
||||
{
|
||||
enum CRStatus status = CR_OK;
|
||||
guchar *result = NULL;
|
||||
GString *stringue = NULL;
|
||||
|
||||
if (!a_this) {
|
||||
result = (guchar *) g_strdup ("NULL");
|
||||
g_return_val_if_fail (result, NULL);
|
||||
return result;
|
||||
}
|
||||
status = cr_font_family_to_string_real (a_this,
|
||||
a_walk_font_family_list,
|
||||
&stringue);
|
||||
|
||||
if (status == CR_OK && stringue) {
|
||||
result = (guchar *) stringue->str;
|
||||
g_string_free (stringue, FALSE);
|
||||
stringue = NULL;
|
||||
|
||||
} else {
|
||||
if (stringue) {
|
||||
g_string_free (stringue, TRUE);
|
||||
stringue = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_font_family_set_name:
|
||||
* @a_this: the current instance of #CRFontFamily.
|
||||
* @a_name: the new name
|
||||
*
|
||||
* Returns CR_OK upon sucessful completion, an error code otherwise.
|
||||
*/
|
||||
enum CRStatus
|
||||
cr_font_family_set_name (CRFontFamily * a_this, guchar * a_name)
|
||||
{
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
|
||||
|
||||
/*
|
||||
*only non generic font families can have a name
|
||||
*/
|
||||
|
||||
if (a_this->type != FONT_FAMILY_NON_GENERIC) {
|
||||
return CR_BAD_PARAM_ERROR;
|
||||
}
|
||||
|
||||
if (a_this->name) {
|
||||
g_free (a_this->name);
|
||||
a_this->name = NULL;
|
||||
}
|
||||
|
||||
a_this->name = a_name;
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_font_family_append:
|
||||
* @a_this: the current instance of #CRFontFamily.
|
||||
* @a_family_to_append: the font family to append to the list
|
||||
*
|
||||
* Returns the new font family list.
|
||||
*/
|
||||
CRFontFamily *
|
||||
cr_font_family_append (CRFontFamily * a_this,
|
||||
CRFontFamily * a_family_to_append)
|
||||
{
|
||||
CRFontFamily *cur_ff = NULL;
|
||||
|
||||
g_return_val_if_fail (a_family_to_append, NULL);
|
||||
|
||||
if (!a_this)
|
||||
return a_family_to_append;
|
||||
|
||||
for (cur_ff = a_this; cur_ff && cur_ff->next; cur_ff = cur_ff->next) ;
|
||||
|
||||
cur_ff->next = a_family_to_append;
|
||||
a_family_to_append->prev = cur_ff;
|
||||
|
||||
return a_this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_font_family_prepend:
|
||||
* @a_this: the current instance #CRFontFamily.
|
||||
* @a_family_to_prepend: the font family to prepend to the list.
|
||||
*
|
||||
* Returns the font family list.
|
||||
*/
|
||||
CRFontFamily *
|
||||
cr_font_family_prepend (CRFontFamily * a_this,
|
||||
CRFontFamily * a_family_to_prepend)
|
||||
{
|
||||
g_return_val_if_fail (a_this && a_family_to_prepend, NULL);
|
||||
|
||||
if (!a_this)
|
||||
return a_family_to_prepend;
|
||||
|
||||
a_family_to_prepend->next = a_this;
|
||||
a_this->prev = a_family_to_prepend;
|
||||
|
||||
return a_family_to_prepend;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_font_family_destroy:
|
||||
* @a_this: the current instance of #CRFontFamily.
|
||||
*
|
||||
* Returns CR_OK upon sucessful completion, an error code otherwise.
|
||||
*/
|
||||
enum CRStatus
|
||||
cr_font_family_destroy (CRFontFamily * a_this)
|
||||
{
|
||||
CRFontFamily *cur_ff = NULL;
|
||||
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
|
||||
|
||||
for (cur_ff = a_this; cur_ff && cur_ff->next; cur_ff = cur_ff->next) ;
|
||||
|
||||
for (; cur_ff; cur_ff = cur_ff->prev) {
|
||||
if (a_this->name) {
|
||||
g_free (a_this->name);
|
||||
a_this->name = NULL;
|
||||
}
|
||||
|
||||
if (cur_ff->next) {
|
||||
g_free (cur_ff->next);
|
||||
|
||||
}
|
||||
|
||||
if (cur_ff->prev == NULL) {
|
||||
g_free (a_this);
|
||||
}
|
||||
}
|
||||
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
/***************************************************
|
||||
*'font-size' manipulation functions definitions
|
||||
***************************************************/
|
||||
|
||||
/**
|
||||
* cr_font_size_new:
|
||||
*
|
||||
* Returns the newly created font size.
|
||||
*/
|
||||
CRFontSize *
|
||||
cr_font_size_new (void)
|
||||
{
|
||||
CRFontSize *result = NULL;
|
||||
|
||||
result = g_try_malloc (sizeof (CRFontSize));
|
||||
if (!result) {
|
||||
cr_utils_trace_info ("Out of memory");
|
||||
return NULL;
|
||||
}
|
||||
memset (result, 0, sizeof (CRFontSize));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_font_size_clear:
|
||||
* @a_this: the current instance of #CRFontSize
|
||||
*
|
||||
* Returns CR_OK upon successful completion, an error code otherwise.
|
||||
*/
|
||||
enum CRStatus
|
||||
cr_font_size_clear (CRFontSize * a_this)
|
||||
{
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
|
||||
|
||||
switch (a_this->type) {
|
||||
case PREDEFINED_ABSOLUTE_FONT_SIZE:
|
||||
case RELATIVE_FONT_SIZE:
|
||||
case INHERITED_FONT_SIZE:
|
||||
memset (a_this, 0, sizeof (CRFontSize));
|
||||
break;
|
||||
|
||||
case ABSOLUTE_FONT_SIZE:
|
||||
memset (a_this, 0, sizeof (CRFontSize));
|
||||
break;
|
||||
|
||||
default:
|
||||
return CR_UNKNOWN_TYPE_ERROR;
|
||||
}
|
||||
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_font_size_copy:
|
||||
* @a_dst: the destination #CRFontSize (where to copy to).
|
||||
* @a_src: the source #CRFontSize (where to copy from).
|
||||
*
|
||||
* Returns CR_OK upon successful completion, an error code otherwise.
|
||||
*/
|
||||
enum CRStatus
|
||||
cr_font_size_copy (CRFontSize * a_dst, CRFontSize const * a_src)
|
||||
{
|
||||
g_return_val_if_fail (a_dst && a_src, CR_BAD_PARAM_ERROR);
|
||||
|
||||
switch (a_src->type) {
|
||||
case PREDEFINED_ABSOLUTE_FONT_SIZE:
|
||||
case RELATIVE_FONT_SIZE:
|
||||
case INHERITED_FONT_SIZE:
|
||||
cr_font_size_clear (a_dst);
|
||||
memcpy (a_dst, a_src, sizeof (CRFontSize));
|
||||
break;
|
||||
|
||||
case ABSOLUTE_FONT_SIZE:
|
||||
cr_font_size_clear (a_dst);
|
||||
cr_num_copy (&a_dst->value.absolute,
|
||||
&a_src->value.absolute);
|
||||
a_dst->type = a_src->type;
|
||||
break;
|
||||
|
||||
default:
|
||||
return CR_UNKNOWN_TYPE_ERROR;
|
||||
}
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_font_size_set_predefined_absolute_font_size:
|
||||
* @a_this: the current instance of #CRFontSize.
|
||||
* @a_predefined: what to set.
|
||||
*
|
||||
* Returns CR_OK upon sucessful completion, an error code otherwise.
|
||||
*/
|
||||
enum CRStatus
|
||||
cr_font_size_set_predefined_absolute_font_size (CRFontSize *a_this,
|
||||
enum CRPredefinedAbsoluteFontSize a_predefined)
|
||||
{
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
|
||||
g_return_val_if_fail (a_predefined >= FONT_SIZE_XX_SMALL
|
||||
&& a_predefined < NB_PREDEFINED_ABSOLUTE_FONT_SIZES,
|
||||
CR_BAD_PARAM_ERROR) ;
|
||||
|
||||
a_this->type = PREDEFINED_ABSOLUTE_FONT_SIZE ;
|
||||
a_this->value.predefined = a_predefined ;
|
||||
|
||||
return CR_OK ;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_font_size_set_relative_font_size:
|
||||
* @a_this: the current instance of #CRFontSize
|
||||
* @a_relative: the new relative font size
|
||||
*
|
||||
* Returns CR_OK upon successful completion, an error code otherwise.
|
||||
*/
|
||||
enum CRStatus
|
||||
cr_font_size_set_relative_font_size (CRFontSize *a_this,
|
||||
enum CRRelativeFontSize a_relative)
|
||||
{
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
|
||||
g_return_val_if_fail (a_relative >= FONT_SIZE_LARGER
|
||||
&& a_relative < NB_RELATIVE_FONT_SIZE,
|
||||
CR_BAD_PARAM_ERROR) ;
|
||||
|
||||
a_this->type = RELATIVE_FONT_SIZE ;
|
||||
a_this->value.relative = a_relative ;
|
||||
return CR_OK ;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_font_size_set_absolute_font_size:
|
||||
* @a_this: the current instance of #CRFontSize
|
||||
* @a_num_type: the type of number to set.
|
||||
* @a_value: the actual value to set.
|
||||
*
|
||||
* Returns CR_OK upon succesful completion, an error code otherwise.
|
||||
*/
|
||||
enum CRStatus
|
||||
cr_font_size_set_absolute_font_size (CRFontSize *a_this,
|
||||
enum CRNumType a_num_type,
|
||||
gdouble a_value)
|
||||
{
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
|
||||
g_return_val_if_fail (a_num_type >= NUM_AUTO
|
||||
&& a_num_type < NB_NUM_TYPE,
|
||||
CR_BAD_PARAM_ERROR) ;
|
||||
|
||||
a_this->type = ABSOLUTE_FONT_SIZE ;
|
||||
cr_num_set (&a_this->value.absolute,
|
||||
a_value, a_num_type) ;
|
||||
return CR_OK ;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_font_size_set_to_inherit:
|
||||
* @a_this: the current instance of #CRFontSize
|
||||
*
|
||||
* Returns CR_OK upon succesful completion, an error code otherwise.
|
||||
*/
|
||||
enum CRStatus
|
||||
cr_font_size_set_to_inherit (CRFontSize *a_this)
|
||||
{
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
|
||||
|
||||
cr_font_size_clear (a_this) ;
|
||||
a_this->type = INHERITED_FONT_SIZE ;
|
||||
|
||||
return CR_OK ;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_font_size_is_set_to_inherit:
|
||||
* @a_this: the current instance of #CRFontSize.
|
||||
*
|
||||
* Returns TRUE if the current instance is set to 'inherit'.
|
||||
*/
|
||||
gboolean
|
||||
cr_font_size_is_set_to_inherit (CRFontSize const *a_this)
|
||||
{
|
||||
g_return_val_if_fail (a_this, FALSE) ;
|
||||
|
||||
return a_this->type == INHERITED_FONT_SIZE ;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_font_size_to_string:
|
||||
* @a_this: the current instance of #CRFontSize
|
||||
*
|
||||
* Returns the serialized form of #CRFontSize. The returned string
|
||||
* has to bee freed using g_free().
|
||||
*/
|
||||
gchar *
|
||||
cr_font_size_to_string (CRFontSize const * a_this)
|
||||
{
|
||||
gchar *str = NULL;
|
||||
|
||||
if (!a_this) {
|
||||
str = g_strdup ("NULL");
|
||||
g_return_val_if_fail (str, NULL);
|
||||
return str;
|
||||
}
|
||||
switch (a_this->type) {
|
||||
case PREDEFINED_ABSOLUTE_FONT_SIZE:
|
||||
str = g_strdup (cr_predefined_absolute_font_size_to_string
|
||||
(a_this->value.predefined));
|
||||
break;
|
||||
case ABSOLUTE_FONT_SIZE:
|
||||
str = (gchar *) cr_num_to_string (&a_this->value.absolute);
|
||||
break;
|
||||
case RELATIVE_FONT_SIZE:
|
||||
str = g_strdup (cr_relative_font_size_to_string
|
||||
(a_this->value.relative));
|
||||
break;
|
||||
case INHERITED_FONT_SIZE:
|
||||
str = g_strdup ("inherit");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_font_size_get_smaller_predefined:
|
||||
* @a_font_size: the font size to consider.
|
||||
* @a_smaller_size: out parameter. The a smaller value than @a_font_size.
|
||||
*/
|
||||
void
|
||||
cr_font_size_get_smaller_predefined_font_size
|
||||
(enum CRPredefinedAbsoluteFontSize a_font_size,
|
||||
enum CRPredefinedAbsoluteFontSize *a_smaller_size)
|
||||
{
|
||||
enum CRPredefinedAbsoluteFontSize result = FONT_SIZE_MEDIUM ;
|
||||
|
||||
g_return_if_fail (a_smaller_size) ;
|
||||
g_return_if_fail (a_font_size < NB_PREDEFINED_ABSOLUTE_FONT_SIZES
|
||||
&& a_font_size >= FONT_SIZE_XX_SMALL) ;
|
||||
|
||||
switch (a_font_size) {
|
||||
case FONT_SIZE_XX_SMALL:
|
||||
result = FONT_SIZE_XX_SMALL ;
|
||||
break ;
|
||||
case FONT_SIZE_X_SMALL:
|
||||
result = FONT_SIZE_XX_SMALL ;
|
||||
break ;
|
||||
case FONT_SIZE_SMALL:
|
||||
result = FONT_SIZE_X_SMALL;
|
||||
break ;
|
||||
case FONT_SIZE_MEDIUM:
|
||||
result = FONT_SIZE_SMALL;
|
||||
break ;
|
||||
case FONT_SIZE_LARGE:
|
||||
result = FONT_SIZE_MEDIUM;
|
||||
break ;
|
||||
case FONT_SIZE_X_LARGE:
|
||||
result = FONT_SIZE_LARGE;
|
||||
break ;
|
||||
case FONT_SIZE_XX_LARGE:
|
||||
result = FONT_SIZE_XX_LARGE;
|
||||
break ;
|
||||
case FONT_SIZE_INHERIT:
|
||||
cr_utils_trace_info ("can't return a smaller size for FONT_SIZE_INHERIT") ;
|
||||
result = FONT_SIZE_MEDIUM ;
|
||||
break ;
|
||||
default:
|
||||
cr_utils_trace_info ("Unknown FONT_SIZE") ;
|
||||
result = FONT_SIZE_MEDIUM ;
|
||||
break ;
|
||||
}
|
||||
*a_smaller_size = result ;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* cr_font_size_get_larger_predefined_font_size:
|
||||
* @a_font_size: the font size to consider.
|
||||
* @a_larger_size: out parameter. the font size considered larger than
|
||||
* @a_font_size.
|
||||
*
|
||||
*/
|
||||
void
|
||||
cr_font_size_get_larger_predefined_font_size
|
||||
(enum CRPredefinedAbsoluteFontSize a_font_size,
|
||||
enum CRPredefinedAbsoluteFontSize *a_larger_size)
|
||||
{
|
||||
enum CRPredefinedAbsoluteFontSize result = FONT_SIZE_MEDIUM ;
|
||||
|
||||
g_return_if_fail (a_larger_size) ;
|
||||
g_return_if_fail (a_font_size >= FONT_SIZE_XX_SMALL
|
||||
&& a_font_size < NB_PREDEFINED_ABSOLUTE_FONT_SIZES) ;
|
||||
|
||||
switch (a_font_size) {
|
||||
case FONT_SIZE_XX_SMALL:
|
||||
result = FONT_SIZE_X_SMALL ;
|
||||
break ;
|
||||
case FONT_SIZE_X_SMALL:
|
||||
result = FONT_SIZE_SMALL ;
|
||||
break ;
|
||||
case FONT_SIZE_SMALL:
|
||||
result = FONT_SIZE_MEDIUM;
|
||||
break ;
|
||||
case FONT_SIZE_MEDIUM:
|
||||
result = FONT_SIZE_LARGE;
|
||||
break ;
|
||||
case FONT_SIZE_LARGE:
|
||||
result = FONT_SIZE_X_LARGE;
|
||||
break ;
|
||||
case FONT_SIZE_X_LARGE:
|
||||
result = FONT_SIZE_XX_LARGE ;
|
||||
break ;
|
||||
case FONT_SIZE_XX_LARGE:
|
||||
result = FONT_SIZE_XX_LARGE;
|
||||
break ;
|
||||
case FONT_SIZE_INHERIT:
|
||||
cr_utils_trace_info ("can't return a bigger size for FONT_SIZE_INHERIT") ;
|
||||
result = FONT_SIZE_MEDIUM ;
|
||||
break ;
|
||||
default:
|
||||
cr_utils_trace_info ("Unknown FONT_SIZE") ;
|
||||
result = FONT_SIZE_MEDIUM ;
|
||||
break ;
|
||||
}
|
||||
*a_larger_size = result ;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_font_size_is_predefined_absolute_font_size:
|
||||
* @a_font_size: the font size to consider.
|
||||
*
|
||||
* Returns TRUE if the instance is an predefined absolute font size, FALSE
|
||||
* otherwise.
|
||||
*/
|
||||
gboolean
|
||||
cr_font_size_is_predefined_absolute_font_size
|
||||
(enum CRPredefinedAbsoluteFontSize a_font_size)
|
||||
{
|
||||
if (a_font_size >= FONT_SIZE_XX_SMALL
|
||||
&& a_font_size < NB_PREDEFINED_ABSOLUTE_FONT_SIZES) {
|
||||
return TRUE ;
|
||||
} else {
|
||||
return FALSE ;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_font_size_adjust_to_string:
|
||||
* @a_this: the instance of #CRFontSizeAdjust.
|
||||
*
|
||||
* Returns the serialized form of #CRFontSizeAdjust
|
||||
*/
|
||||
gchar *
|
||||
cr_font_size_adjust_to_string (CRFontSizeAdjust const * a_this)
|
||||
{
|
||||
gchar *str = NULL;
|
||||
|
||||
if (!a_this) {
|
||||
str = g_strdup ("NULL");
|
||||
g_return_val_if_fail (str, NULL);
|
||||
return str;
|
||||
}
|
||||
|
||||
switch (a_this->type) {
|
||||
case FONT_SIZE_ADJUST_NONE:
|
||||
str = g_strdup ("none");
|
||||
break;
|
||||
case FONT_SIZE_ADJUST_NUMBER:
|
||||
if (a_this->num)
|
||||
str = (gchar *) cr_num_to_string (a_this->num);
|
||||
else
|
||||
str = g_strdup ("unknown font-size-adjust property value"); /* Should raise an error no?*/
|
||||
break;
|
||||
case FONT_SIZE_ADJUST_INHERIT:
|
||||
str = g_strdup ("inherit");
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_font_style_to_string:
|
||||
* @a_code: the current instance of #CRFontStyle .
|
||||
*
|
||||
* Returns the serialized #CRFontStyle. The caller must free the returned
|
||||
* string using g_free().
|
||||
*/
|
||||
const gchar *
|
||||
cr_font_style_to_string (enum CRFontStyle a_code)
|
||||
{
|
||||
gchar *str = NULL;
|
||||
|
||||
switch (a_code) {
|
||||
case FONT_STYLE_NORMAL:
|
||||
str = (gchar *) "normal";
|
||||
break;
|
||||
case FONT_STYLE_ITALIC:
|
||||
str = (gchar *) "italic";
|
||||
break;
|
||||
case FONT_STYLE_OBLIQUE:
|
||||
str = (gchar *) "oblique";
|
||||
break;
|
||||
case FONT_STYLE_INHERIT:
|
||||
str = (gchar *) "inherit";
|
||||
break;
|
||||
default:
|
||||
str = (gchar *) "unknown font style value";
|
||||
break;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_font_variant_to_string:
|
||||
* @a_code: the current instance of #CRFontVariant.
|
||||
*
|
||||
* Returns the serialized form of #CRFontVariant. The caller has
|
||||
* to free the returned string using g_free().
|
||||
*/
|
||||
const gchar *
|
||||
cr_font_variant_to_string (enum CRFontVariant a_code)
|
||||
{
|
||||
gchar *str = NULL;
|
||||
|
||||
switch (a_code) {
|
||||
case FONT_VARIANT_NORMAL:
|
||||
str = (gchar *) "normal";
|
||||
break;
|
||||
case FONT_VARIANT_SMALL_CAPS:
|
||||
str = (gchar *) "small-caps";
|
||||
break;
|
||||
case FONT_VARIANT_INHERIT:
|
||||
str = (gchar *) "inherit";
|
||||
break;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_font_weight_get_bolder:
|
||||
* @a_weight: the #CRFontWeight to consider.
|
||||
*
|
||||
* Returns a font weight bolder than @a_weight
|
||||
*/
|
||||
enum CRFontWeight
|
||||
cr_font_weight_get_bolder (enum CRFontWeight a_weight)
|
||||
{
|
||||
if (a_weight == FONT_WEIGHT_INHERIT) {
|
||||
cr_utils_trace_info ("can't return a bolder weight for FONT_WEIGHT_INHERIT") ;
|
||||
return a_weight;
|
||||
} else if (a_weight >= FONT_WEIGHT_900) {
|
||||
return FONT_WEIGHT_900 ;
|
||||
} else if (a_weight < FONT_WEIGHT_NORMAL) {
|
||||
return FONT_WEIGHT_NORMAL ;
|
||||
} else if (a_weight == FONT_WEIGHT_BOLDER
|
||||
|| a_weight == FONT_WEIGHT_LIGHTER) {
|
||||
cr_utils_trace_info ("FONT_WEIGHT_BOLDER or FONT_WEIGHT_LIGHTER should not appear here") ;
|
||||
return FONT_WEIGHT_NORMAL ;
|
||||
} else {
|
||||
return a_weight << 1 ;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_font_weight_to_string:
|
||||
* @a_code: the font weight to consider.
|
||||
*
|
||||
* Returns the serialized form of #CRFontWeight.
|
||||
*/
|
||||
const gchar *
|
||||
cr_font_weight_to_string (enum CRFontWeight a_code)
|
||||
{
|
||||
gchar *str = NULL;
|
||||
|
||||
switch (a_code) {
|
||||
case FONT_WEIGHT_NORMAL:
|
||||
str = (gchar *) "normal";
|
||||
break;
|
||||
case FONT_WEIGHT_BOLD:
|
||||
str = (gchar *) "bold";
|
||||
break;
|
||||
case FONT_WEIGHT_BOLDER:
|
||||
str = (gchar *) "bolder";
|
||||
break;
|
||||
case FONT_WEIGHT_LIGHTER:
|
||||
str = (gchar *) "lighter";
|
||||
break;
|
||||
case FONT_WEIGHT_100:
|
||||
str = (gchar *) "100";
|
||||
break;
|
||||
case FONT_WEIGHT_200:
|
||||
str = (gchar *) "200";
|
||||
break;
|
||||
case FONT_WEIGHT_300:
|
||||
str = (gchar *) "300";
|
||||
break;
|
||||
case FONT_WEIGHT_400:
|
||||
str = (gchar *) "400";
|
||||
break;
|
||||
case FONT_WEIGHT_500:
|
||||
str = (gchar *) "500";
|
||||
break;
|
||||
case FONT_WEIGHT_600:
|
||||
str = (gchar *) "600";
|
||||
break;
|
||||
case FONT_WEIGHT_700:
|
||||
str = (gchar *) "700";
|
||||
break;
|
||||
case FONT_WEIGHT_800:
|
||||
str = (gchar *) "800";
|
||||
break;
|
||||
case FONT_WEIGHT_900:
|
||||
str = (gchar *) "900";
|
||||
break;
|
||||
case FONT_WEIGHT_INHERIT:
|
||||
str = (gchar *) "inherit";
|
||||
break;
|
||||
default:
|
||||
str = (gchar *) "unknown font-weight property value";
|
||||
break;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_font_stretch_to_string:
|
||||
* @a_code: the instance of #CRFontStretch to consider.
|
||||
*
|
||||
* Returns the serialized form of #CRFontStretch.
|
||||
*/
|
||||
const gchar *
|
||||
cr_font_stretch_to_string (enum CRFontStretch a_code)
|
||||
{
|
||||
gchar *str = NULL;
|
||||
|
||||
switch (a_code) {
|
||||
case FONT_STRETCH_NORMAL:
|
||||
str = (gchar *) "normal";
|
||||
break;
|
||||
case FONT_STRETCH_WIDER:
|
||||
str = (gchar *) "wider";
|
||||
break;
|
||||
case FONT_STRETCH_NARROWER:
|
||||
str = (gchar *) "narrower";
|
||||
break;
|
||||
case FONT_STRETCH_ULTRA_CONDENSED:
|
||||
str = (gchar *) "ultra-condensed";
|
||||
break;
|
||||
case FONT_STRETCH_EXTRA_CONDENSED:
|
||||
str = (gchar *) "extra-condensed";
|
||||
break;
|
||||
case FONT_STRETCH_CONDENSED:
|
||||
str = (gchar *) "condensed";
|
||||
break;
|
||||
case FONT_STRETCH_SEMI_CONDENSED:
|
||||
str = (gchar *) "semi-condensed";
|
||||
break;
|
||||
case FONT_STRETCH_SEMI_EXPANDED:
|
||||
str = (gchar *) "semi-expanded";
|
||||
break;
|
||||
case FONT_STRETCH_EXPANDED:
|
||||
str = (gchar *) "expanded";
|
||||
break;
|
||||
case FONT_STRETCH_EXTRA_EXPANDED:
|
||||
str = (gchar *) "extra-expaned";
|
||||
break;
|
||||
case FONT_STRETCH_ULTRA_EXPANDED:
|
||||
str = (gchar *) "ultra-expanded";
|
||||
break;
|
||||
case FONT_STRETCH_INHERIT:
|
||||
str = (gchar *) "inherit";
|
||||
break;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_font_size_destroy:
|
||||
* @a_font_size: the font size to destroy
|
||||
*
|
||||
*/
|
||||
void
|
||||
cr_font_size_destroy (CRFontSize * a_font_size)
|
||||
{
|
||||
g_return_if_fail (a_font_size);
|
||||
|
||||
g_free (a_font_size) ;
|
||||
}
|
||||
|
||||
/*******************************************************
|
||||
*'font-size-adjust' manipulation function definition
|
||||
*******************************************************/
|
||||
|
||||
/**
|
||||
* cr_font_size_adjust_new:
|
||||
*
|
||||
* Returns a newly built instance of #CRFontSizeAdjust
|
||||
*/
|
||||
CRFontSizeAdjust *
|
||||
cr_font_size_adjust_new (void)
|
||||
{
|
||||
CRFontSizeAdjust *result = NULL;
|
||||
|
||||
result = g_try_malloc (sizeof (CRFontSizeAdjust));
|
||||
if (!result) {
|
||||
cr_utils_trace_info ("Out of memory");
|
||||
return NULL;
|
||||
}
|
||||
memset (result, 0, sizeof (CRFontSizeAdjust));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_font_size_adjust_destroy:
|
||||
* @a_this: the current instance of #CRFontSizeAdjust.
|
||||
*
|
||||
*/
|
||||
void
|
||||
cr_font_size_adjust_destroy (CRFontSizeAdjust * a_this)
|
||||
{
|
||||
g_return_if_fail (a_this);
|
||||
|
||||
if (a_this->type == FONT_SIZE_ADJUST_NUMBER && a_this->num) {
|
||||
cr_num_destroy (a_this->num);
|
||||
a_this->num = NULL;
|
||||
}
|
||||
}
|
315
src/st/croco/cr-fonts.h
Normal file
315
src/st/croco/cr-fonts.h
Normal file
@ -0,0 +1,315 @@
|
||||
/* -*- Mode: C; indent-tabs-mode:nil; c-basic-offset: 8-*- */
|
||||
|
||||
/*
|
||||
* This file is part of The Croco Library
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of version 2.1 of
|
||||
* the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the
|
||||
* GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*
|
||||
* Author: Dodji Seketeli
|
||||
* See COPYRIGHTS file for copyright information.
|
||||
*/
|
||||
|
||||
#ifndef __CR_FONTS_H__
|
||||
#define __CR_FONTS_H__
|
||||
|
||||
#include "cr-utils.h"
|
||||
#include "cr-num.h"
|
||||
|
||||
/**
|
||||
*@file
|
||||
*Various type declarations about font selection related
|
||||
*properties.
|
||||
*/
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
||||
enum CRFontFamilyType
|
||||
{
|
||||
FONT_FAMILY_SANS_SERIF,
|
||||
FONT_FAMILY_SERIF,
|
||||
FONT_FAMILY_CURSIVE,
|
||||
FONT_FAMILY_FANTASY,
|
||||
FONT_FAMILY_MONOSPACE,
|
||||
FONT_FAMILY_NON_GENERIC,
|
||||
FONT_FAMILY_INHERIT,
|
||||
/**/
|
||||
NB_FONT_FAMILIE_TYPES
|
||||
} ;
|
||||
|
||||
typedef struct _CRFontFamily CRFontFamily ;
|
||||
|
||||
struct _CRFontFamily
|
||||
{
|
||||
enum CRFontFamilyType type ;
|
||||
|
||||
/*
|
||||
*The name of the font family, in case
|
||||
*it is non generic.
|
||||
*Is set only if the type is FONT_FAMILY_NON_GENERIC.
|
||||
*/
|
||||
guchar *name ;
|
||||
|
||||
CRFontFamily *next ;
|
||||
CRFontFamily *prev ;
|
||||
} ;
|
||||
|
||||
|
||||
/**
|
||||
*The different types
|
||||
*of absolute font size.
|
||||
*This is used by the 'font-size'
|
||||
*property defined in css2 spec
|
||||
*in chapter 15.2.4 .
|
||||
*These values a indexes of
|
||||
*table of size so please, do not
|
||||
*change their definition order unless
|
||||
*you know what you are doing.
|
||||
*/
|
||||
enum CRPredefinedAbsoluteFontSize
|
||||
{
|
||||
FONT_SIZE_XX_SMALL=0,
|
||||
FONT_SIZE_X_SMALL,
|
||||
FONT_SIZE_SMALL,
|
||||
FONT_SIZE_MEDIUM,
|
||||
FONT_SIZE_LARGE,
|
||||
FONT_SIZE_X_LARGE,
|
||||
FONT_SIZE_XX_LARGE,
|
||||
FONT_SIZE_INHERIT,
|
||||
NB_PREDEFINED_ABSOLUTE_FONT_SIZES
|
||||
} ;
|
||||
|
||||
/**
|
||||
*The different types
|
||||
*of relative font size.
|
||||
*This is used by the 'font-size'
|
||||
*property defined in css2 spec
|
||||
*in chapter 15.2.4 .
|
||||
*These values a indexes of
|
||||
*table of size so please, do not
|
||||
*change their definition order unless
|
||||
*you know what you are doing.
|
||||
*/
|
||||
enum CRRelativeFontSize
|
||||
{
|
||||
FONT_SIZE_LARGER,
|
||||
FONT_SIZE_SMALLER,
|
||||
NB_RELATIVE_FONT_SIZE
|
||||
} ;
|
||||
|
||||
/**
|
||||
*The type of font-size property.
|
||||
*Used to define the type of #CRFontSize .
|
||||
*See css2 spec chapter 15.2.4 to understand.
|
||||
*/
|
||||
enum CRFontSizeType {
|
||||
/**
|
||||
*If the type of #CRFontSize is
|
||||
*PREDEFINED_ABSOLUTE_FONT_SIZE,
|
||||
*the CRFontSize::value.predefined_absolute
|
||||
*field will be defined.
|
||||
*/
|
||||
PREDEFINED_ABSOLUTE_FONT_SIZE,
|
||||
|
||||
/**
|
||||
*If the type of #CRFontSize is
|
||||
*ABSOLUTE_FONT_SIZE,
|
||||
*the CRFontSize::value.absolute
|
||||
*field will be defined.
|
||||
*/
|
||||
ABSOLUTE_FONT_SIZE,
|
||||
|
||||
/**
|
||||
*If the type of #CRFontSize is
|
||||
*RELATIVE_FONT_SIZE,
|
||||
*the CRFontSize::value.relative
|
||||
*field will be defined.
|
||||
*/
|
||||
RELATIVE_FONT_SIZE,
|
||||
|
||||
/**
|
||||
*If the type of #CRFontSize is
|
||||
*INHERITED_FONT_SIZE,
|
||||
*the None of the field of the CRFontSize::value enum
|
||||
*will be defined.
|
||||
*/
|
||||
INHERITED_FONT_SIZE,
|
||||
|
||||
NB_FONT_SIZE_TYPE
|
||||
} ;
|
||||
|
||||
typedef struct _CRFontSize CRFontSize ;
|
||||
struct _CRFontSize {
|
||||
enum CRFontSizeType type ;
|
||||
union {
|
||||
enum CRPredefinedAbsoluteFontSize predefined ;
|
||||
enum CRRelativeFontSize relative ;
|
||||
CRNum absolute ;
|
||||
} value;
|
||||
} ;
|
||||
|
||||
enum CRFontSizeAdjustType
|
||||
{
|
||||
FONT_SIZE_ADJUST_NONE = 0,
|
||||
FONT_SIZE_ADJUST_NUMBER,
|
||||
FONT_SIZE_ADJUST_INHERIT
|
||||
} ;
|
||||
typedef struct _CRFontSizeAdjust CRFontSizeAdjust ;
|
||||
struct _CRFontSizeAdjust
|
||||
{
|
||||
enum CRFontSizeAdjustType type ;
|
||||
CRNum *num ;
|
||||
} ;
|
||||
|
||||
enum CRFontStyle
|
||||
{
|
||||
FONT_STYLE_NORMAL=0,
|
||||
FONT_STYLE_ITALIC,
|
||||
FONT_STYLE_OBLIQUE,
|
||||
FONT_STYLE_INHERIT
|
||||
} ;
|
||||
|
||||
enum CRFontVariant
|
||||
{
|
||||
FONT_VARIANT_NORMAL=0,
|
||||
FONT_VARIANT_SMALL_CAPS,
|
||||
FONT_VARIANT_INHERIT
|
||||
} ;
|
||||
|
||||
enum CRFontWeight
|
||||
{
|
||||
FONT_WEIGHT_NORMAL = 1,
|
||||
FONT_WEIGHT_BOLD = 1<<1,
|
||||
FONT_WEIGHT_BOLDER = 1<<2,
|
||||
FONT_WEIGHT_LIGHTER = 1<<3,
|
||||
FONT_WEIGHT_100 = 1<<4,
|
||||
FONT_WEIGHT_200 = 1<<5,
|
||||
FONT_WEIGHT_300 = 1<<6,
|
||||
FONT_WEIGHT_400 = 1<<7,
|
||||
FONT_WEIGHT_500 = 1<<8,
|
||||
FONT_WEIGHT_600 = 1<<9,
|
||||
FONT_WEIGHT_700 = 1<<10,
|
||||
FONT_WEIGHT_800 = 1<<11,
|
||||
FONT_WEIGHT_900 = 1<<12,
|
||||
FONT_WEIGHT_INHERIT = 1<<13,
|
||||
NB_FONT_WEIGHTS
|
||||
} ;
|
||||
|
||||
enum CRFontStretch
|
||||
{
|
||||
FONT_STRETCH_NORMAL=0,
|
||||
FONT_STRETCH_WIDER,
|
||||
FONT_STRETCH_NARROWER,
|
||||
FONT_STRETCH_ULTRA_CONDENSED,
|
||||
FONT_STRETCH_EXTRA_CONDENSED,
|
||||
FONT_STRETCH_CONDENSED,
|
||||
FONT_STRETCH_SEMI_CONDENSED,
|
||||
FONT_STRETCH_SEMI_EXPANDED,
|
||||
FONT_STRETCH_EXPANDED,
|
||||
FONT_STRETCH_EXTRA_EXPANDED,
|
||||
FONT_STRETCH_ULTRA_EXPANDED,
|
||||
FONT_STRETCH_INHERIT
|
||||
} ;
|
||||
|
||||
/**************************************
|
||||
*'font-family' manipulation functions
|
||||
***************************************/
|
||||
CRFontFamily *
|
||||
cr_font_family_new (enum CRFontFamilyType a_type, guchar *a_name) ;
|
||||
|
||||
CRFontFamily *
|
||||
cr_font_family_append (CRFontFamily *a_this,
|
||||
CRFontFamily *a_family_to_append) ;
|
||||
|
||||
guchar *
|
||||
cr_font_family_to_string (CRFontFamily const *a_this,
|
||||
gboolean a_walk_font_family_list) ;
|
||||
|
||||
CRFontFamily *
|
||||
cr_font_family_prepend (CRFontFamily *a_this,
|
||||
CRFontFamily *a_family_to_prepend);
|
||||
|
||||
enum CRStatus
|
||||
cr_font_family_destroy (CRFontFamily *a_this) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_font_family_set_name (CRFontFamily *a_this, guchar *a_name) ;
|
||||
|
||||
|
||||
/************************************
|
||||
*'font-size' manipulation functions
|
||||
***********************************/
|
||||
|
||||
CRFontSize * cr_font_size_new (void) ;
|
||||
|
||||
enum CRStatus cr_font_size_clear (CRFontSize *a_this) ;
|
||||
|
||||
enum CRStatus cr_font_size_copy (CRFontSize *a_dst,
|
||||
CRFontSize const *a_src) ;
|
||||
enum CRStatus cr_font_size_set_predefined_absolute_font_size (CRFontSize *a_this,
|
||||
enum CRPredefinedAbsoluteFontSize a_predefined) ;
|
||||
enum CRStatus cr_font_size_set_relative_font_size (CRFontSize *a_this,
|
||||
enum CRRelativeFontSize a_relative) ;
|
||||
|
||||
enum CRStatus cr_font_size_set_absolute_font_size (CRFontSize *a_this,
|
||||
enum CRNumType a_num_type,
|
||||
gdouble a_value) ;
|
||||
|
||||
enum CRStatus cr_font_size_set_to_inherit (CRFontSize *a_this) ;
|
||||
|
||||
gboolean cr_font_size_is_set_to_inherit (CRFontSize const *a_this) ;
|
||||
|
||||
gchar* cr_font_size_to_string (CRFontSize const *a_this) ;
|
||||
|
||||
void cr_font_size_destroy (CRFontSize *a_font_size) ;
|
||||
|
||||
/*******************************************************
|
||||
*'font-size-adjust' manipulation function declarations
|
||||
*******************************************************/
|
||||
|
||||
CRFontSizeAdjust * cr_font_size_adjust_new (void) ;
|
||||
|
||||
gchar * cr_font_size_adjust_to_string (CRFontSizeAdjust const *a_this) ;
|
||||
|
||||
void cr_font_size_adjust_destroy (CRFontSizeAdjust *a_this) ;
|
||||
|
||||
void
|
||||
cr_font_size_get_smaller_predefined_font_size (enum CRPredefinedAbsoluteFontSize a_font_size,
|
||||
enum CRPredefinedAbsoluteFontSize *a_smaller_size) ;
|
||||
void
|
||||
cr_font_size_get_larger_predefined_font_size (enum CRPredefinedAbsoluteFontSize a_font_size,
|
||||
enum CRPredefinedAbsoluteFontSize *a_larger_size) ;
|
||||
|
||||
gboolean
|
||||
cr_font_size_is_predefined_absolute_font_size (enum CRPredefinedAbsoluteFontSize a_font_size) ;
|
||||
|
||||
/***********************************
|
||||
*various other font related functions
|
||||
***********************************/
|
||||
const gchar * cr_font_style_to_string (enum CRFontStyle a_code) ;
|
||||
|
||||
const gchar * cr_font_weight_to_string (enum CRFontWeight a_code) ;
|
||||
|
||||
enum CRFontWeight
|
||||
cr_font_weight_get_bolder (enum CRFontWeight a_weight) ;
|
||||
|
||||
const gchar * cr_font_variant_to_string (enum CRFontVariant a_code) ;
|
||||
|
||||
const gchar * cr_font_stretch_to_string (enum CRFontStretch a_code) ;
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif
|
1191
src/st/croco/cr-input.c
Normal file
1191
src/st/croco/cr-input.c
Normal file
File diff suppressed because it is too large
Load Diff
174
src/st/croco/cr-input.h
Normal file
174
src/st/croco/cr-input.h
Normal file
@ -0,0 +1,174 @@
|
||||
/* -*- Mode: C; indent-tabs-mode:nil; c-basic-offset:8 -*- */
|
||||
|
||||
/*
|
||||
* This file is part of The Croco Library
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of version 2.1 of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*
|
||||
* Author: Dodji Seketeli
|
||||
* See the COPYRIGHTS file for copyrights information.
|
||||
*/
|
||||
|
||||
#ifndef __CR_INPUT_SRC_H__
|
||||
#define __CR_INPUT_SRC_H__
|
||||
|
||||
|
||||
#include <glib.h>
|
||||
#include "cr-utils.h"
|
||||
#include "cr-parsing-location.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/**
|
||||
*@file
|
||||
*The libcroco basic input stream class
|
||||
*declaration file.
|
||||
*/
|
||||
|
||||
typedef struct _CRInput CRInput ;
|
||||
typedef struct _CRInputPriv CRInputPriv ;
|
||||
|
||||
/**
|
||||
*The #CRInput class provides the abstraction of
|
||||
*an utf8-encoded character stream.
|
||||
*/
|
||||
struct _CRInput
|
||||
{
|
||||
CRInputPriv *priv ;
|
||||
} ;
|
||||
|
||||
typedef struct _CRInputPos CRInputPos ;
|
||||
|
||||
struct _CRInputPos
|
||||
{
|
||||
glong line ;
|
||||
glong col ;
|
||||
gboolean end_of_file ;
|
||||
gboolean end_of_line ;
|
||||
glong next_byte_index ;
|
||||
} ;
|
||||
|
||||
CRInput *
|
||||
cr_input_new_from_buf (guchar *a_buf, gulong a_len,
|
||||
enum CREncoding a_enc, gboolean a_free_buf) ;
|
||||
CRInput *
|
||||
cr_input_new_from_uri (const gchar *a_file_uri,
|
||||
enum CREncoding a_enc) ;
|
||||
|
||||
void
|
||||
cr_input_destroy (CRInput *a_this) ;
|
||||
|
||||
void
|
||||
cr_input_ref (CRInput *a_this) ;
|
||||
|
||||
gboolean
|
||||
cr_input_unref (CRInput *a_this) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_input_read_byte (CRInput *a_this, guchar *a_byte) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_input_read_char (CRInput *a_this, guint32 *a_char) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_input_consume_chars (CRInput *a_this, guint32 a_char,
|
||||
gulong *a_nb_char) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_input_consume_char (CRInput *a_this, guint32 a_char) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_input_consume_white_spaces (CRInput *a_this, gulong *a_nb_chars) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_input_peek_byte (CRInput const *a_this, enum CRSeekPos a_origin,
|
||||
gulong a_offset, guchar *a_byte) ;
|
||||
|
||||
guchar
|
||||
cr_input_peek_byte2 (CRInput const *a_this, gulong a_offset,
|
||||
gboolean *a_eof) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_input_peek_char (CRInput const *a_this, guint32 *a_char) ;
|
||||
|
||||
guchar *
|
||||
cr_input_get_byte_addr (CRInput *a_this,
|
||||
gulong a_offset) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_input_get_cur_byte_addr (CRInput *a_this, guchar ** a_offset) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_input_seek_index (CRInput *a_this,
|
||||
enum CRSeekPos a_origin, gint a_pos) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_input_get_cur_index (CRInput const *a_this, glong *a_index) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_input_set_cur_index (CRInput *a_this, glong a_index) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_input_get_cur_pos (CRInput const *a_this, CRInputPos * a_pos) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_input_set_cur_pos (CRInput *a_this, CRInputPos const *a_pos) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_input_get_parsing_location (CRInput const *a_this,
|
||||
CRParsingLocation *a_loc) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_input_get_end_of_line (CRInput const *a_this, gboolean *a_eol) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_input_set_end_of_line (CRInput *a_this, gboolean a_eol) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_input_get_end_of_file (CRInput const *a_this, gboolean *a_eof) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_input_set_end_of_file (CRInput *a_this, gboolean a_eof) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_input_set_line_num (CRInput *a_this, glong a_line_num) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_input_get_line_num (CRInput const *a_this, glong *a_line_num) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_input_set_column_num (CRInput *a_this, glong a_col) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_input_get_column_num (CRInput const *a_this, glong *a_col) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_input_increment_line_num (CRInput *a_this,
|
||||
glong a_increment) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_input_increment_col_num (CRInput *a_this,
|
||||
glong a_increment) ;
|
||||
|
||||
glong
|
||||
cr_input_get_nb_bytes_left (CRInput const *a_this) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_input_end_of_input (CRInput const *a_this, gboolean *a_end_of_input) ;
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /*__CR_INPUT_SRC_H__*/
|
||||
|
313
src/st/croco/cr-num.c
Normal file
313
src/st/croco/cr-num.c
Normal file
@ -0,0 +1,313 @@
|
||||
/* -*- Mode: C; indent-tabs-mode:nil; c-basic-offset: 8-*- */
|
||||
|
||||
/*
|
||||
* This file is part of The Croco Library
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of version 2.1 of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*
|
||||
* Author: Dodji Seketeli
|
||||
* See COPYRIGHTS file for copyrights information.
|
||||
*/
|
||||
|
||||
/**
|
||||
*@CRNum:
|
||||
*
|
||||
*The definition
|
||||
*of the #CRNum class.
|
||||
*/
|
||||
|
||||
#include "cr-num.h"
|
||||
#include "string.h"
|
||||
|
||||
/**
|
||||
* cr_num_new:
|
||||
*
|
||||
*#CRNum.
|
||||
*
|
||||
*Returns the newly built instance of
|
||||
*#CRNum.
|
||||
*/
|
||||
CRNum *
|
||||
cr_num_new (void)
|
||||
{
|
||||
CRNum *result = NULL;
|
||||
|
||||
result = g_try_malloc (sizeof (CRNum));
|
||||
|
||||
if (result == NULL) {
|
||||
cr_utils_trace_info ("Out of memory");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset (result, 0, sizeof (CRNum));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_num_new_with_val:
|
||||
* @a_val: the numerical value of the number.
|
||||
* @a_type: the type of number.
|
||||
*
|
||||
* A constructor of #CRNum.
|
||||
*
|
||||
* Returns the newly built instance of #CRNum or
|
||||
* NULL if an error arises.
|
||||
*/
|
||||
CRNum *
|
||||
cr_num_new_with_val (gdouble a_val, enum CRNumType a_type)
|
||||
{
|
||||
CRNum *result = NULL;
|
||||
|
||||
result = cr_num_new ();
|
||||
|
||||
g_return_val_if_fail (result, NULL);
|
||||
|
||||
result->val = a_val;
|
||||
result->type = a_type;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_num_to_string:
|
||||
*@a_this: the current instance of #CRNum.
|
||||
*
|
||||
*Returns the newly built string representation
|
||||
*of the current instance of #CRNum. The returned
|
||||
*string is NULL terminated. The caller *must*
|
||||
*free the returned string.
|
||||
*/
|
||||
guchar *
|
||||
cr_num_to_string (CRNum const * a_this)
|
||||
{
|
||||
gdouble test_val = 0.0;
|
||||
|
||||
guchar *tmp_char1 = NULL,
|
||||
*tmp_char2 = NULL,
|
||||
*result = NULL;
|
||||
|
||||
g_return_val_if_fail (a_this, NULL);
|
||||
|
||||
test_val = a_this->val - (glong) a_this->val;
|
||||
|
||||
if (!test_val) {
|
||||
tmp_char1 = (guchar *) g_strdup_printf ("%ld", (glong) a_this->val);
|
||||
} else {
|
||||
tmp_char1 = (guchar *) g_new0 (char, G_ASCII_DTOSTR_BUF_SIZE + 1);
|
||||
if (tmp_char1 != NULL)
|
||||
g_ascii_dtostr ((gchar *) tmp_char1, G_ASCII_DTOSTR_BUF_SIZE, a_this->val);
|
||||
}
|
||||
|
||||
g_return_val_if_fail (tmp_char1, NULL);
|
||||
|
||||
switch (a_this->type) {
|
||||
case NUM_LENGTH_EM:
|
||||
tmp_char2 = (guchar *) "em";
|
||||
break;
|
||||
|
||||
case NUM_LENGTH_EX:
|
||||
tmp_char2 = (guchar *) "ex";
|
||||
break;
|
||||
|
||||
case NUM_LENGTH_PX:
|
||||
tmp_char2 = (guchar *) "px";
|
||||
break;
|
||||
|
||||
case NUM_LENGTH_IN:
|
||||
tmp_char2 = (guchar *) "in";
|
||||
break;
|
||||
|
||||
case NUM_LENGTH_CM:
|
||||
tmp_char2 = (guchar *) "cm";
|
||||
break;
|
||||
|
||||
case NUM_LENGTH_MM:
|
||||
tmp_char2 = (guchar *) "mm";
|
||||
break;
|
||||
|
||||
case NUM_LENGTH_PT:
|
||||
tmp_char2 = (guchar *) "pt";
|
||||
break;
|
||||
|
||||
case NUM_LENGTH_PC:
|
||||
tmp_char2 = (guchar *) "pc";
|
||||
break;
|
||||
|
||||
case NUM_ANGLE_DEG:
|
||||
tmp_char2 = (guchar *) "deg";
|
||||
break;
|
||||
|
||||
case NUM_ANGLE_RAD:
|
||||
tmp_char2 = (guchar *) "rad";
|
||||
break;
|
||||
|
||||
case NUM_ANGLE_GRAD:
|
||||
tmp_char2 = (guchar *) "grad";
|
||||
break;
|
||||
|
||||
case NUM_TIME_MS:
|
||||
tmp_char2 = (guchar *) "ms";
|
||||
break;
|
||||
|
||||
case NUM_TIME_S:
|
||||
tmp_char2 = (guchar *) "s";
|
||||
break;
|
||||
|
||||
case NUM_FREQ_HZ:
|
||||
tmp_char2 = (guchar *) "Hz";
|
||||
break;
|
||||
|
||||
case NUM_FREQ_KHZ:
|
||||
tmp_char2 = (guchar *) "KHz";
|
||||
break;
|
||||
|
||||
case NUM_PERCENTAGE:
|
||||
tmp_char2 = (guchar *) "%";
|
||||
break;
|
||||
case NUM_INHERIT:
|
||||
tmp_char2 = (guchar *) "inherit";
|
||||
break ;
|
||||
case NUM_AUTO:
|
||||
tmp_char2 = (guchar *) "auto";
|
||||
break ;
|
||||
case NUM_GENERIC:
|
||||
tmp_char2 = NULL ;
|
||||
break ;
|
||||
default:
|
||||
tmp_char2 = (guchar *) "unknown";
|
||||
break;
|
||||
}
|
||||
|
||||
if (tmp_char2) {
|
||||
result = (guchar *) g_strconcat ((gchar *) tmp_char1, tmp_char2, NULL);
|
||||
g_free (tmp_char1);
|
||||
} else {
|
||||
result = tmp_char1;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_num_copy:
|
||||
*@a_src: the instance of #CRNum to copy.
|
||||
*Must be non NULL.
|
||||
*@a_dest: the destination of the copy.
|
||||
*Must be non NULL
|
||||
*
|
||||
*Copies an instance of #CRNum.
|
||||
*
|
||||
*Returns CR_OK upon successful completion, an
|
||||
*error code otherwise.
|
||||
*/
|
||||
enum CRStatus
|
||||
cr_num_copy (CRNum * a_dest, CRNum const * a_src)
|
||||
{
|
||||
g_return_val_if_fail (a_dest && a_src, CR_BAD_PARAM_ERROR);
|
||||
|
||||
memcpy (a_dest, a_src, sizeof (CRNum));
|
||||
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_num_dup:
|
||||
*@a_this: the instance of #CRNum to duplicate.
|
||||
*
|
||||
*Duplicates an instance of #CRNum
|
||||
*
|
||||
*Returns the newly created (duplicated) instance of #CRNum.
|
||||
*Must be freed by cr_num_destroy().
|
||||
*/
|
||||
CRNum *
|
||||
cr_num_dup (CRNum const * a_this)
|
||||
{
|
||||
CRNum *result = NULL;
|
||||
enum CRStatus status = CR_OK;
|
||||
|
||||
g_return_val_if_fail (a_this, NULL);
|
||||
|
||||
result = cr_num_new ();
|
||||
g_return_val_if_fail (result, NULL);
|
||||
|
||||
status = cr_num_copy (result, a_this);
|
||||
g_return_val_if_fail (status == CR_OK, NULL);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_num_set:
|
||||
*Sets an instance of #CRNum.
|
||||
*@a_this: the current instance of #CRNum to be set.
|
||||
*@a_val: the new numerical value to be hold by the current
|
||||
*instance of #CRNum
|
||||
*@a_type: the new type of #CRNum.
|
||||
*
|
||||
* Returns CR_OK upon succesful completion, an error code otherwise.
|
||||
*/
|
||||
enum CRStatus
|
||||
cr_num_set (CRNum * a_this, gdouble a_val, enum CRNumType a_type)
|
||||
{
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
|
||||
|
||||
a_this->val = a_val;
|
||||
a_this->type = a_type;
|
||||
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_num_is_fixed_length:
|
||||
* @a_this: the current instance of #CRNum .
|
||||
*
|
||||
*Tests if the current instance of #CRNum is a fixed
|
||||
*length value or not. Typically a fixed length value
|
||||
*is anything from NUM_LENGTH_EM to NUM_LENGTH_PC.
|
||||
*See the definition of #CRNumType to see what we mean.
|
||||
*
|
||||
*Returns TRUE if the instance of #CRNum is a fixed length number,
|
||||
*FALSE otherwise.
|
||||
*/
|
||||
gboolean
|
||||
cr_num_is_fixed_length (CRNum const * a_this)
|
||||
{
|
||||
gboolean result = FALSE;
|
||||
|
||||
g_return_val_if_fail (a_this, FALSE);
|
||||
|
||||
if (a_this->type >= NUM_LENGTH_EM
|
||||
&& a_this->type <= NUM_LENGTH_PC) {
|
||||
result = TRUE ;
|
||||
}
|
||||
return result ;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_num_destroy:
|
||||
*@a_this: the this pointer of
|
||||
*the current instance of #CRNum.
|
||||
*
|
||||
*The destructor of #CRNum.
|
||||
*/
|
||||
void
|
||||
cr_num_destroy (CRNum * a_this)
|
||||
{
|
||||
g_return_if_fail (a_this);
|
||||
|
||||
g_free (a_this);
|
||||
}
|
127
src/st/croco/cr-num.h
Normal file
127
src/st/croco/cr-num.h
Normal file
@ -0,0 +1,127 @@
|
||||
/* -*- Mode: C; indent-tabs-mode:nil; c-basic-offset: 8-*- */
|
||||
|
||||
/*
|
||||
* This file is part of The Croco Library
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of version 2.1 of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*
|
||||
* Author: Dodji Seketeli
|
||||
* See COPYRIGHTS file for copyright information
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
*@file
|
||||
*The declaration
|
||||
*of the #CRNum class.
|
||||
*/
|
||||
|
||||
#ifndef __CR_NUM_H__
|
||||
#define __CR_NUM_H__
|
||||
|
||||
#include <glib.h>
|
||||
#include "cr-utils.h"
|
||||
#include "cr-parsing-location.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/**
|
||||
*@file
|
||||
*The declaration of the #CRNum class.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
*The different types
|
||||
*of numbers.
|
||||
*Please, do not modify
|
||||
*the declaration order of the enum
|
||||
*members, unless you know
|
||||
*what you are doing.
|
||||
*/
|
||||
enum CRNumType
|
||||
{
|
||||
NUM_AUTO = 0,
|
||||
NUM_GENERIC,
|
||||
NUM_LENGTH_EM,
|
||||
NUM_LENGTH_EX,
|
||||
NUM_LENGTH_PX,
|
||||
NUM_LENGTH_IN,
|
||||
NUM_LENGTH_CM,
|
||||
NUM_LENGTH_MM,
|
||||
NUM_LENGTH_PT,
|
||||
NUM_LENGTH_PC,
|
||||
NUM_ANGLE_DEG,
|
||||
NUM_ANGLE_RAD,
|
||||
NUM_ANGLE_GRAD,
|
||||
NUM_TIME_MS,
|
||||
NUM_TIME_S,
|
||||
NUM_FREQ_HZ,
|
||||
NUM_FREQ_KHZ,
|
||||
NUM_PERCENTAGE,
|
||||
NUM_INHERIT,
|
||||
NUM_UNKNOWN_TYPE,
|
||||
NB_NUM_TYPE
|
||||
} ;
|
||||
|
||||
|
||||
/**
|
||||
*An abstraction of a number (num)
|
||||
*as defined in the css2 spec.
|
||||
*/
|
||||
typedef struct _CRNum CRNum ;
|
||||
|
||||
/**
|
||||
*An abstraction of a number (num)
|
||||
*as defined in the css2 spec.
|
||||
*/
|
||||
struct _CRNum
|
||||
{
|
||||
enum CRNumType type ;
|
||||
gdouble val ;
|
||||
CRParsingLocation location ;
|
||||
} ;
|
||||
|
||||
CRNum *
|
||||
cr_num_new (void) ;
|
||||
|
||||
CRNum *
|
||||
cr_num_new_with_val (gdouble a_val,
|
||||
enum CRNumType a_type) ;
|
||||
|
||||
CRNum *
|
||||
cr_num_dup (CRNum const *a_this) ;
|
||||
|
||||
guchar *
|
||||
cr_num_to_string (CRNum const *a_this) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_num_copy (CRNum *a_dest, CRNum const *a_src) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_num_set (CRNum *a_this, gdouble a_val,
|
||||
enum CRNumType a_type) ;
|
||||
|
||||
gboolean
|
||||
cr_num_is_fixed_length (CRNum const *a_this) ;
|
||||
|
||||
void
|
||||
cr_num_destroy (CRNum *a_this) ;
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
||||
#endif /*__CR_NUM_H__*/
|
1142
src/st/croco/cr-om-parser.c
Normal file
1142
src/st/croco/cr-om-parser.c
Normal file
File diff suppressed because it is too large
Load Diff
98
src/st/croco/cr-om-parser.h
Normal file
98
src/st/croco/cr-om-parser.h
Normal file
@ -0,0 +1,98 @@
|
||||
/* -*- Mode: C; indent-tabs-mode:nil; c-basic-offset: 8-*- */
|
||||
|
||||
/*
|
||||
* This file is part of The Croco Library
|
||||
*
|
||||
* Copyright (C) 2002-2003 Dodji Seketeli <dodji@seketeli.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of version 2.1 of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the
|
||||
* GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*/
|
||||
|
||||
/*
|
||||
*$Id$
|
||||
*/
|
||||
|
||||
#ifndef __CR_OM_PARSER_H__
|
||||
#define __CR_OM_PARSER_H__
|
||||
|
||||
#include "cr-parser.h"
|
||||
#include "cr-cascade.h"
|
||||
|
||||
|
||||
/**
|
||||
*@file
|
||||
*The definition of the CSS Object Model Parser.
|
||||
*This parser uses (and sits) the SAC api of libcroco defined
|
||||
*in cr-parser.h and cr-doc-handler.h
|
||||
*/
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _CROMParser CROMParser ;
|
||||
typedef struct _CROMParserPriv CROMParserPriv ;
|
||||
|
||||
/**
|
||||
*The Object model parser.
|
||||
*Can parse a css file and build a css object model.
|
||||
*This parser uses an instance of #CRParser and defines
|
||||
*a set of SAC callbacks to build the Object Model.
|
||||
*/
|
||||
struct _CROMParser
|
||||
{
|
||||
CROMParserPriv *priv ;
|
||||
} ;
|
||||
|
||||
CROMParser * cr_om_parser_new (CRInput *a_input) ;
|
||||
|
||||
|
||||
enum CRStatus cr_om_parser_simply_parse_file (const guchar *a_file_path,
|
||||
enum CREncoding a_enc,
|
||||
CRStyleSheet **a_result) ;
|
||||
|
||||
enum CRStatus cr_om_parser_parse_file (CROMParser *a_this,
|
||||
const guchar *a_file_uri,
|
||||
enum CREncoding a_enc,
|
||||
CRStyleSheet **a_result) ;
|
||||
|
||||
enum CRStatus cr_om_parser_simply_parse_buf (const guchar *a_buf,
|
||||
gulong a_len,
|
||||
enum CREncoding a_enc,
|
||||
CRStyleSheet **a_result) ;
|
||||
|
||||
enum CRStatus cr_om_parser_parse_buf (CROMParser *a_this,
|
||||
const guchar *a_buf,
|
||||
gulong a_len,
|
||||
enum CREncoding a_enc,
|
||||
CRStyleSheet **a_result) ;
|
||||
|
||||
enum CRStatus cr_om_parser_parse_paths_to_cascade (CROMParser *a_this,
|
||||
const guchar *a_author_path,
|
||||
const guchar *a_user_path,
|
||||
const guchar *a_ua_path,
|
||||
enum CREncoding a_encoding,
|
||||
CRCascade ** a_result) ;
|
||||
|
||||
enum CRStatus cr_om_parser_simply_parse_paths_to_cascade (const guchar *a_author_path,
|
||||
const guchar *a_user_path,
|
||||
const guchar *a_ua_path,
|
||||
enum CREncoding a_encoding,
|
||||
CRCascade ** a_result) ;
|
||||
|
||||
void cr_om_parser_destroy (CROMParser *a_this) ;
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /*__CR_OM_PARSER_H__*/
|
4525
src/st/croco/cr-parser.c
Normal file
4525
src/st/croco/cr-parser.c
Normal file
File diff suppressed because it is too large
Load Diff
128
src/st/croco/cr-parser.h
Normal file
128
src/st/croco/cr-parser.h
Normal file
@ -0,0 +1,128 @@
|
||||
/* -*- Mode: C; indent-tabs-mode:nil; c-basic-offset: 8-*- */
|
||||
|
||||
/*
|
||||
* This file is part of The Croco Library
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of version 2.1 of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*
|
||||
* Author: Dodji Seketeli
|
||||
* See COPYRIGHTS file for copyrights information.
|
||||
*/
|
||||
|
||||
#ifndef __CR_PARSER_H__
|
||||
#define __CR_PARSER_H__
|
||||
|
||||
#include <glib.h>
|
||||
#include "cr-input.h"
|
||||
#include "cr-tknzr.h"
|
||||
#include "cr-utils.h"
|
||||
#include "cr-doc-handler.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/**
|
||||
*@file
|
||||
*The declaration file
|
||||
*of the #CRParser class.
|
||||
*/
|
||||
typedef struct _CRParser CRParser ;
|
||||
typedef struct _CRParserPriv CRParserPriv ;
|
||||
|
||||
|
||||
/**
|
||||
*The implementation of
|
||||
*the SAC parser.
|
||||
*The Class is opaque
|
||||
*and must be manipulated through
|
||||
*the provided methods.
|
||||
*/
|
||||
struct _CRParser {
|
||||
CRParserPriv *priv ;
|
||||
} ;
|
||||
|
||||
|
||||
CRParser * cr_parser_new (CRTknzr *a_tknzr) ;
|
||||
|
||||
CRParser * cr_parser_new_from_buf (guchar *a_buf, gulong a_len,
|
||||
enum CREncoding a_enc,
|
||||
gboolean a_free_buf) ;
|
||||
|
||||
CRParser * cr_parser_new_from_file (const guchar *a_file_uri,
|
||||
enum CREncoding a_enc) ;
|
||||
|
||||
CRParser * cr_parser_new_from_input (CRInput *a_input) ;
|
||||
|
||||
enum CRStatus cr_parser_set_tknzr (CRParser *a_this, CRTknzr *a_tknzr) ;
|
||||
|
||||
enum CRStatus cr_parser_get_tknzr (CRParser *a_this, CRTknzr **a_tknzr) ;
|
||||
|
||||
enum CRStatus cr_parser_get_parsing_location (CRParser const *a_this, CRParsingLocation *a_loc) ;
|
||||
|
||||
enum CRStatus cr_parser_try_to_skip_spaces_and_comments (CRParser *a_this) ;
|
||||
|
||||
|
||||
enum CRStatus cr_parser_set_sac_handler (CRParser *a_this,
|
||||
CRDocHandler *a_handler) ;
|
||||
|
||||
enum CRStatus cr_parser_get_sac_handler (CRParser *a_this,
|
||||
CRDocHandler **a_handler) ;
|
||||
|
||||
enum CRStatus cr_parser_set_use_core_grammar (CRParser *a_this,
|
||||
gboolean a_use_core_grammar) ;
|
||||
enum CRStatus cr_parser_get_use_core_grammar (CRParser const *a_this,
|
||||
gboolean *a_use_core_grammar) ;
|
||||
|
||||
enum CRStatus cr_parser_parse (CRParser *a_this) ;
|
||||
|
||||
enum CRStatus cr_parser_parse_file (CRParser *a_this,
|
||||
const guchar *a_file_uri,
|
||||
enum CREncoding a_enc) ;
|
||||
|
||||
enum CRStatus cr_parser_parse_buf (CRParser *a_this, const guchar *a_buf,
|
||||
gulong a_len, enum CREncoding a_enc) ;
|
||||
|
||||
enum CRStatus cr_parser_set_default_sac_handler (CRParser *a_this) ;
|
||||
|
||||
enum CRStatus cr_parser_parse_term (CRParser *a_this, CRTerm **a_term) ;
|
||||
|
||||
enum CRStatus cr_parser_parse_expr (CRParser *a_this, CRTerm **a_expr) ;
|
||||
|
||||
enum CRStatus cr_parser_parse_prio (CRParser *a_this, CRString **a_prio) ;
|
||||
|
||||
enum CRStatus cr_parser_parse_declaration (CRParser *a_this, CRString **a_property,
|
||||
CRTerm **a_expr, gboolean *a_important) ;
|
||||
|
||||
enum CRStatus cr_parser_parse_statement_core (CRParser *a_this) ;
|
||||
|
||||
enum CRStatus cr_parser_parse_ruleset (CRParser *a_this) ;
|
||||
|
||||
enum CRStatus cr_parser_parse_import (CRParser *a_this, GList ** a_media_list,
|
||||
CRString **a_import_string,
|
||||
CRParsingLocation *a_location) ;
|
||||
|
||||
enum CRStatus cr_parser_parse_media (CRParser *a_this) ;
|
||||
|
||||
enum CRStatus cr_parser_parse_page (CRParser *a_this) ;
|
||||
|
||||
enum CRStatus cr_parser_parse_charset (CRParser *a_this, CRString **a_value,
|
||||
CRParsingLocation *a_charset_sym_location) ;
|
||||
|
||||
enum CRStatus cr_parser_parse_font_face (CRParser *a_this) ;
|
||||
|
||||
void cr_parser_destroy (CRParser *a_this) ;
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /*__CR_PARSER_H__*/
|
172
src/st/croco/cr-parsing-location.c
Normal file
172
src/st/croco/cr-parsing-location.c
Normal file
@ -0,0 +1,172 @@
|
||||
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
|
||||
|
||||
/*
|
||||
* This file is part of The Croco Library
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of version 2.1 of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*
|
||||
* Author: Dodji Seketeli.
|
||||
* See the COPYRIGHTS file for copyright information.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "cr-parsing-location.h"
|
||||
|
||||
/**
|
||||
*@CRParsingLocation:
|
||||
*
|
||||
*Definition of the #CRparsingLocation class.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* cr_parsing_location_new:
|
||||
*Instanciates a new parsing location.
|
||||
*
|
||||
*Returns the newly instanciated #CRParsingLocation.
|
||||
*Must be freed by cr_parsing_location_destroy()
|
||||
*/
|
||||
CRParsingLocation *
|
||||
cr_parsing_location_new (void)
|
||||
{
|
||||
CRParsingLocation * result = NULL ;
|
||||
|
||||
result = g_try_malloc (sizeof (CRParsingLocation)) ;
|
||||
if (!result) {
|
||||
cr_utils_trace_info ("Out of memory error") ;
|
||||
return NULL ;
|
||||
}
|
||||
cr_parsing_location_init (result) ;
|
||||
return result ;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_parsing_location_init:
|
||||
*@a_this: the current instance of #CRParsingLocation.
|
||||
*
|
||||
*Initializes the an instance of #CRparsingLocation.
|
||||
*
|
||||
*Returns CR_OK upon succesful completion, an error code otherwise.
|
||||
*/
|
||||
enum CRStatus
|
||||
cr_parsing_location_init (CRParsingLocation *a_this)
|
||||
{
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
|
||||
|
||||
memset (a_this, 0, sizeof (CRParsingLocation)) ;
|
||||
return CR_OK ;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_parsing_location_copy:
|
||||
*@a_to: the destination of the copy.
|
||||
*Must be allocated by the caller.
|
||||
*@a_from: the source of the copy.
|
||||
*
|
||||
*Copies an instance of CRParsingLocation into another one.
|
||||
*
|
||||
*Returns CR_OK upon succesful completion, an error code
|
||||
*otherwise.
|
||||
*/
|
||||
enum CRStatus
|
||||
cr_parsing_location_copy (CRParsingLocation *a_to,
|
||||
CRParsingLocation const *a_from)
|
||||
{
|
||||
g_return_val_if_fail (a_to && a_from, CR_BAD_PARAM_ERROR) ;
|
||||
|
||||
memcpy (a_to, a_from, sizeof (CRParsingLocation)) ;
|
||||
return CR_OK ;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_parsing_location_to_string:
|
||||
*@a_this: the current instance of #CRParsingLocation.
|
||||
*@a_mask: a bitmap that defines which parts of the
|
||||
*parsing location are to be serialized (line, column or byte offset)
|
||||
*
|
||||
*Returns the serialized string or NULL in case of an error.
|
||||
*/
|
||||
gchar *
|
||||
cr_parsing_location_to_string (CRParsingLocation const *a_this,
|
||||
enum CRParsingLocationSerialisationMask a_mask)
|
||||
{
|
||||
GString *result = NULL ;
|
||||
gchar *str = NULL ;
|
||||
|
||||
g_return_val_if_fail (a_this, NULL) ;
|
||||
|
||||
if (!a_mask) {
|
||||
a_mask = DUMP_LINE | DUMP_COLUMN | DUMP_BYTE_OFFSET ;
|
||||
}
|
||||
result =g_string_new (NULL) ;
|
||||
if (!result)
|
||||
return NULL ;
|
||||
if (a_mask & DUMP_LINE) {
|
||||
g_string_append_printf (result, "line:%d ",
|
||||
a_this->line) ;
|
||||
}
|
||||
if (a_mask & DUMP_COLUMN) {
|
||||
g_string_append_printf (result, "column:%d ",
|
||||
a_this->column) ;
|
||||
}
|
||||
if (a_mask & DUMP_BYTE_OFFSET) {
|
||||
g_string_append_printf (result, "byte offset:%d ",
|
||||
a_this->byte_offset) ;
|
||||
}
|
||||
if (result->len) {
|
||||
str = result->str ;
|
||||
g_string_free (result, FALSE) ;
|
||||
} else {
|
||||
g_string_free (result, TRUE) ;
|
||||
}
|
||||
return str ;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_parsing_location_dump:
|
||||
* @a_this: current instance of #CRParsingLocation
|
||||
* @a_mask: the serialization mask.
|
||||
* @a_fp: the file pointer to dump the parsing location to.
|
||||
*/
|
||||
void
|
||||
cr_parsing_location_dump (CRParsingLocation const *a_this,
|
||||
enum CRParsingLocationSerialisationMask a_mask,
|
||||
FILE *a_fp)
|
||||
{
|
||||
gchar *str = NULL ;
|
||||
|
||||
g_return_if_fail (a_this && a_fp) ;
|
||||
str = cr_parsing_location_to_string (a_this, a_mask) ;
|
||||
if (str) {
|
||||
fprintf (a_fp, "%s", str) ;
|
||||
g_free (str) ;
|
||||
str = NULL ;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_parsing_location_destroy:
|
||||
*@a_this: the current instance of #CRParsingLocation. Must
|
||||
*have been allocated with cr_parsing_location_new().
|
||||
*
|
||||
*Destroys the current instance of #CRParsingLocation
|
||||
*/
|
||||
void
|
||||
cr_parsing_location_destroy (CRParsingLocation *a_this)
|
||||
{
|
||||
g_return_if_fail (a_this) ;
|
||||
g_free (a_this) ;
|
||||
}
|
||||
|
70
src/st/croco/cr-parsing-location.h
Normal file
70
src/st/croco/cr-parsing-location.h
Normal file
@ -0,0 +1,70 @@
|
||||
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
|
||||
|
||||
/*
|
||||
* This file is part of The Croco Library
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of version 2.1 of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*
|
||||
* Author: Dodji Seketeli.
|
||||
* See the COPYRIGHTS file for copyright information.
|
||||
*/
|
||||
|
||||
#ifndef __CR_PARSING_LOCATION_H__
|
||||
#define __CR_PARSING_LOCATION_H__
|
||||
|
||||
#include "cr-utils.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/**
|
||||
*@file
|
||||
*The declaration of the CRParsingLocation
|
||||
*object. This object keeps track of line/column/byte offset/
|
||||
*at which the parsing of a given CSS construction appears.
|
||||
*/
|
||||
|
||||
typedef struct _CRParsingLocation CRParsingLocation;
|
||||
struct _CRParsingLocation {
|
||||
guint line ;
|
||||
guint column ;
|
||||
guint byte_offset ;
|
||||
} ;
|
||||
|
||||
|
||||
enum CRParsingLocationSerialisationMask {
|
||||
DUMP_LINE = 1,
|
||||
DUMP_COLUMN = 1 << 1,
|
||||
DUMP_BYTE_OFFSET = 1 << 2
|
||||
} ;
|
||||
|
||||
CRParsingLocation * cr_parsing_location_new (void) ;
|
||||
|
||||
enum CRStatus cr_parsing_location_init (CRParsingLocation *a_this) ;
|
||||
|
||||
enum CRStatus cr_parsing_location_copy (CRParsingLocation *a_to,
|
||||
CRParsingLocation const *a_from) ;
|
||||
|
||||
gchar * cr_parsing_location_to_string (CRParsingLocation const *a_this,
|
||||
enum CRParsingLocationSerialisationMask a_mask) ;
|
||||
void cr_parsing_location_dump (CRParsingLocation const *a_this,
|
||||
enum CRParsingLocationSerialisationMask a_mask,
|
||||
FILE *a_fp) ;
|
||||
|
||||
void cr_parsing_location_destroy (CRParsingLocation *a_this) ;
|
||||
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
#endif
|
404
src/st/croco/cr-prop-list.c
Normal file
404
src/st/croco/cr-prop-list.c
Normal file
@ -0,0 +1,404 @@
|
||||
/*
|
||||
* This file is part of The Croco Library
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of version 2.1 of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*
|
||||
* Author: Dodji Seketeli
|
||||
* See COPYRIGHTS file for copyrights information.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "cr-prop-list.h"
|
||||
|
||||
#define PRIVATE(a_obj) (a_obj)->priv
|
||||
|
||||
struct _CRPropListPriv {
|
||||
CRString *prop;
|
||||
CRDeclaration *decl;
|
||||
CRPropList *next;
|
||||
CRPropList *prev;
|
||||
};
|
||||
|
||||
static CRPropList *cr_prop_list_allocate (void);
|
||||
|
||||
/**
|
||||
*Default allocator of CRPropList
|
||||
*@return the newly allocated CRPropList or NULL
|
||||
*if an error arises.
|
||||
*/
|
||||
static CRPropList *
|
||||
cr_prop_list_allocate (void)
|
||||
{
|
||||
CRPropList *result = NULL;
|
||||
|
||||
result = g_try_malloc (sizeof (CRPropList));
|
||||
if (!result) {
|
||||
cr_utils_trace_info ("could not allocate CRPropList");
|
||||
return NULL;
|
||||
}
|
||||
memset (result, 0, sizeof (CRPropList));
|
||||
PRIVATE (result) = g_try_malloc (sizeof (CRPropListPriv));
|
||||
if (!result) {
|
||||
cr_utils_trace_info ("could not allocate CRPropListPriv");
|
||||
g_free (result);
|
||||
return NULL;
|
||||
}
|
||||
memset (PRIVATE (result), 0, sizeof (CRPropListPriv));
|
||||
return result;
|
||||
}
|
||||
|
||||
/****************
|
||||
*public methods
|
||||
***************/
|
||||
|
||||
/**
|
||||
* cr_prop_list_append:
|
||||
*@a_this: the current instance of #CRPropList
|
||||
*@a_to_append: the property list to append
|
||||
*
|
||||
*Appends a property list to the current one.
|
||||
*
|
||||
*Returns the resulting prop list, or NULL if an error
|
||||
*occurred
|
||||
*/
|
||||
CRPropList *
|
||||
cr_prop_list_append (CRPropList * a_this, CRPropList * a_to_append)
|
||||
{
|
||||
CRPropList *cur = NULL;
|
||||
|
||||
g_return_val_if_fail (a_to_append, NULL);
|
||||
|
||||
if (!a_this)
|
||||
return a_to_append;
|
||||
|
||||
/*go fetch the last element of the list */
|
||||
for (cur = a_this;
|
||||
cur && PRIVATE (cur) && PRIVATE (cur)->next;
|
||||
cur = PRIVATE (cur)->next) ;
|
||||
g_return_val_if_fail (cur, NULL);
|
||||
PRIVATE (cur)->next = a_to_append;
|
||||
PRIVATE (a_to_append)->prev = cur;
|
||||
return a_this;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_prop_list_append2:
|
||||
*Appends a pair of prop/declaration to
|
||||
*the current prop list.
|
||||
*@a_this: the current instance of #CRPropList
|
||||
*@a_prop: the property to consider
|
||||
*@a_decl: the declaration to consider
|
||||
*
|
||||
*Returns the resulting property list, or NULL in case
|
||||
*of an error.
|
||||
*/
|
||||
CRPropList *
|
||||
cr_prop_list_append2 (CRPropList * a_this,
|
||||
CRString * a_prop,
|
||||
CRDeclaration * a_decl)
|
||||
{
|
||||
CRPropList *list = NULL,
|
||||
*result = NULL;
|
||||
|
||||
g_return_val_if_fail (a_prop && a_decl, NULL);
|
||||
|
||||
list = cr_prop_list_allocate ();
|
||||
g_return_val_if_fail (list && PRIVATE (list), NULL);
|
||||
|
||||
PRIVATE (list)->prop = a_prop;
|
||||
PRIVATE (list)->decl = a_decl;
|
||||
|
||||
result = cr_prop_list_append (a_this, list);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_prop_list_prepend:
|
||||
*@a_this: the current instance of #CRPropList
|
||||
*@a_to_prepend: the new list to prepend.
|
||||
*
|
||||
*Prepends a list to the current list
|
||||
*Returns the new properties list.
|
||||
*/
|
||||
CRPropList *
|
||||
cr_prop_list_prepend (CRPropList * a_this, CRPropList * a_to_prepend)
|
||||
{
|
||||
CRPropList *cur = NULL;
|
||||
|
||||
g_return_val_if_fail (a_to_prepend, NULL);
|
||||
|
||||
if (!a_this)
|
||||
return a_to_prepend;
|
||||
|
||||
for (cur = a_to_prepend; cur && PRIVATE (cur)->next;
|
||||
cur = PRIVATE (cur)->next) ;
|
||||
g_return_val_if_fail (cur, NULL);
|
||||
PRIVATE (cur)->next = a_this;
|
||||
PRIVATE (a_this)->prev = cur;
|
||||
return a_to_prepend;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_prop_list_prepend2:
|
||||
*@a_this: the current instance of #CRPropList
|
||||
*@a_prop_name: property name to append
|
||||
*@a_decl: the property value to append.
|
||||
*
|
||||
*Prepends a propertie to a list of properties
|
||||
*
|
||||
*Returns the new property list.
|
||||
*/
|
||||
CRPropList *
|
||||
cr_prop_list_prepend2 (CRPropList * a_this,
|
||||
CRString * a_prop_name, CRDeclaration * a_decl)
|
||||
{
|
||||
CRPropList *list = NULL,
|
||||
*result = NULL;
|
||||
|
||||
g_return_val_if_fail (a_this && PRIVATE (a_this)
|
||||
&& a_prop_name && a_decl, NULL);
|
||||
|
||||
list = cr_prop_list_allocate ();
|
||||
g_return_val_if_fail (list, NULL);
|
||||
PRIVATE (list)->prop = a_prop_name;
|
||||
PRIVATE (list)->decl = a_decl;
|
||||
result = cr_prop_list_prepend (a_this, list);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_prop_list_set_prop:
|
||||
*@a_this: the current instance of #CRPropList
|
||||
*@a_prop: the property to set
|
||||
*
|
||||
*Sets the property of a CRPropList
|
||||
*/
|
||||
enum CRStatus
|
||||
cr_prop_list_set_prop (CRPropList * a_this, CRString * a_prop)
|
||||
{
|
||||
g_return_val_if_fail (a_this && PRIVATE (a_this)
|
||||
&& a_prop, CR_BAD_PARAM_ERROR);
|
||||
|
||||
PRIVATE (a_this)->prop = a_prop;
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_prop_list_get_prop:
|
||||
*@a_this: the current instance of #CRPropList
|
||||
*@a_prop: out parameter. The returned property
|
||||
*
|
||||
*Getter of the property associated to the current instance
|
||||
*of #CRPropList
|
||||
*
|
||||
*Returns CR_OK upon successful completion, an error code
|
||||
*otherwise.
|
||||
*/
|
||||
enum CRStatus
|
||||
cr_prop_list_get_prop (CRPropList const * a_this, CRString ** a_prop)
|
||||
{
|
||||
g_return_val_if_fail (a_this && PRIVATE (a_this)
|
||||
&& a_prop, CR_BAD_PARAM_ERROR);
|
||||
|
||||
*a_prop = PRIVATE (a_this)->prop;
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_prop_list_set_decl:
|
||||
* @a_this: the current instance of #CRPropList
|
||||
* @a_decl: the new property value.
|
||||
*
|
||||
* Returns CR_OK upon successful completion, an error code otherwise.
|
||||
*/
|
||||
enum CRStatus
|
||||
cr_prop_list_set_decl (CRPropList * a_this, CRDeclaration * a_decl)
|
||||
{
|
||||
g_return_val_if_fail (a_this && PRIVATE (a_this)
|
||||
&& a_decl, CR_BAD_PARAM_ERROR);
|
||||
|
||||
PRIVATE (a_this)->decl = a_decl;
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_prop_list_get_decl:
|
||||
* @a_this: the current instance of #CRPropList
|
||||
* @a_decl: out parameter. The property value
|
||||
*
|
||||
* Returns CR_OK upon successful completion.
|
||||
*/
|
||||
enum CRStatus
|
||||
cr_prop_list_get_decl (CRPropList const * a_this, CRDeclaration ** a_decl)
|
||||
{
|
||||
g_return_val_if_fail (a_this && PRIVATE (a_this)
|
||||
&& a_decl, CR_BAD_PARAM_ERROR);
|
||||
|
||||
*a_decl = PRIVATE (a_this)->decl;
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_prop_list_lookup_prop:
|
||||
*@a_this: the current instance of #CRPropList
|
||||
*@a_prop: the property to lookup
|
||||
*@a_prop_list: out parameter. The property/declaration
|
||||
*pair found (if and only if the function returned code if CR_OK)
|
||||
*
|
||||
*Lookup a given property/declaration pair
|
||||
*
|
||||
*Returns CR_OK if a prop/decl pair has been found,
|
||||
*CR_VALUE_NOT_FOUND_ERROR if not, or an error code if something
|
||||
*bad happens.
|
||||
*/
|
||||
enum CRStatus
|
||||
cr_prop_list_lookup_prop (CRPropList * a_this,
|
||||
CRString * a_prop, CRPropList ** a_pair)
|
||||
{
|
||||
CRPropList *cur = NULL;
|
||||
|
||||
g_return_val_if_fail (a_prop && a_pair, CR_BAD_PARAM_ERROR);
|
||||
|
||||
if (!a_this)
|
||||
return CR_VALUE_NOT_FOUND_ERROR;
|
||||
|
||||
g_return_val_if_fail (PRIVATE (a_this), CR_BAD_PARAM_ERROR);
|
||||
|
||||
for (cur = a_this; cur; cur = PRIVATE (cur)->next) {
|
||||
if (PRIVATE (cur)->prop
|
||||
&& PRIVATE (cur)->prop->stryng
|
||||
&& PRIVATE (cur)->prop->stryng->str
|
||||
&& a_prop->stryng
|
||||
&& a_prop->stryng->str
|
||||
&& !strcmp (PRIVATE (cur)->prop->stryng->str,
|
||||
a_prop->stryng->str))
|
||||
break;
|
||||
}
|
||||
|
||||
if (cur) {
|
||||
*a_pair = cur;
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
return CR_VALUE_NOT_FOUND_ERROR;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_prop_list_get_next:
|
||||
*@a_this: the current instance of CRPropList
|
||||
*
|
||||
*Gets the next prop/decl pair in the list
|
||||
*
|
||||
*Returns the next prop/declaration pair of the list,
|
||||
*or NULL if we reached end of list (or if an error occurs)
|
||||
*/
|
||||
CRPropList *
|
||||
cr_prop_list_get_next (CRPropList * a_this)
|
||||
{
|
||||
g_return_val_if_fail (a_this && PRIVATE (a_this), NULL);
|
||||
|
||||
return PRIVATE (a_this)->next;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_prop_list_get_prev:
|
||||
*@a_this: the current instance of CRPropList
|
||||
*
|
||||
*Gets the previous prop/decl pair in the list
|
||||
*
|
||||
*Returns the previous prop/declaration pair of the list,
|
||||
*or NULL if we reached end of list (or if an error occurs)
|
||||
*/
|
||||
CRPropList *
|
||||
cr_prop_list_get_prev (CRPropList * a_this)
|
||||
{
|
||||
g_return_val_if_fail (a_this && PRIVATE (a_this), NULL);
|
||||
|
||||
return PRIVATE (a_this)->prev;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_prop_list_unlink:
|
||||
*@a_this: the current list of prop/decl pairs
|
||||
*@a_pair: the prop/decl pair to unlink.
|
||||
*
|
||||
*Unlinks a prop/decl pair from the list
|
||||
*
|
||||
*Returns the new list or NULL in case of an error.
|
||||
*/
|
||||
CRPropList *
|
||||
cr_prop_list_unlink (CRPropList * a_this, CRPropList * a_pair)
|
||||
{
|
||||
CRPropList *prev = NULL,
|
||||
*next = NULL;
|
||||
|
||||
g_return_val_if_fail (a_this && PRIVATE (a_this) && a_pair, NULL);
|
||||
|
||||
/*some sanity checks */
|
||||
if (PRIVATE (a_pair)->next) {
|
||||
next = PRIVATE (a_pair)->next;
|
||||
g_return_val_if_fail (PRIVATE (next), NULL);
|
||||
g_return_val_if_fail (PRIVATE (next)->prev == a_pair, NULL);
|
||||
}
|
||||
if (PRIVATE (a_pair)->prev) {
|
||||
prev = PRIVATE (a_pair)->prev;
|
||||
g_return_val_if_fail (PRIVATE (prev), NULL);
|
||||
g_return_val_if_fail (PRIVATE (prev)->next == a_pair, NULL);
|
||||
}
|
||||
if (prev) {
|
||||
PRIVATE (prev)->next = next;
|
||||
}
|
||||
if (next) {
|
||||
PRIVATE (next)->prev = prev;
|
||||
}
|
||||
PRIVATE (a_pair)->prev = PRIVATE (a_pair)->next = NULL;
|
||||
if (a_this == a_pair) {
|
||||
if (next)
|
||||
return next;
|
||||
return NULL;
|
||||
}
|
||||
return a_this;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_prop_list_destroy:
|
||||
* @a_this: the current instance of #CRPropList
|
||||
*/
|
||||
void
|
||||
cr_prop_list_destroy (CRPropList * a_this)
|
||||
{
|
||||
CRPropList *tail = NULL,
|
||||
*cur = NULL;
|
||||
|
||||
g_return_if_fail (a_this && PRIVATE (a_this));
|
||||
|
||||
for (tail = a_this;
|
||||
tail && PRIVATE (tail) && PRIVATE (tail)->next;
|
||||
tail = cr_prop_list_get_next (tail)) ;
|
||||
g_return_if_fail (tail);
|
||||
|
||||
cur = tail;
|
||||
|
||||
while (cur) {
|
||||
tail = PRIVATE (cur)->prev;
|
||||
if (tail && PRIVATE (tail))
|
||||
PRIVATE (tail)->next = NULL;
|
||||
PRIVATE (cur)->prev = NULL;
|
||||
g_free (PRIVATE (cur));
|
||||
PRIVATE (cur) = NULL;
|
||||
g_free (cur);
|
||||
cur = tail;
|
||||
}
|
||||
}
|
80
src/st/croco/cr-prop-list.h
Normal file
80
src/st/croco/cr-prop-list.h
Normal file
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* This file is part of The Croco Library
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of version 2.1 of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*
|
||||
* Author: Dodji Seketeli
|
||||
* See COPYRIGHTS file for copyrights information.
|
||||
*/
|
||||
|
||||
#ifndef __CR_PROP_LIST_H__
|
||||
#define __CR_PROP_LIST_H__
|
||||
|
||||
#include "cr-utils.h"
|
||||
#include "cr-declaration.h"
|
||||
#include "cr-string.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _CRPropList CRPropList ;
|
||||
typedef struct _CRPropListPriv CRPropListPriv ;
|
||||
|
||||
struct _CRPropList
|
||||
{
|
||||
CRPropListPriv * priv;
|
||||
} ;
|
||||
|
||||
CRPropList * cr_prop_list_append (CRPropList *a_this,
|
||||
CRPropList *a_to_append) ;
|
||||
|
||||
CRPropList * cr_prop_list_append2 (CRPropList *a_this,
|
||||
CRString *a_prop,
|
||||
CRDeclaration *a_decl) ;
|
||||
|
||||
CRPropList * cr_prop_list_prepend (CRPropList *a_this,
|
||||
CRPropList *a_to_append) ;
|
||||
|
||||
CRPropList * cr_prop_list_prepend2 (CRPropList *a_this,
|
||||
CRString *a_prop,
|
||||
CRDeclaration *a_decl) ;
|
||||
|
||||
enum CRStatus cr_prop_list_set_prop (CRPropList *a_this,
|
||||
CRString *a_prop) ;
|
||||
|
||||
enum CRStatus cr_prop_list_get_prop (CRPropList const *a_this,
|
||||
CRString **a_prop) ;
|
||||
|
||||
enum CRStatus cr_prop_list_lookup_prop (CRPropList *a_this,
|
||||
CRString *a_prop,
|
||||
CRPropList**a_pair) ;
|
||||
|
||||
CRPropList * cr_prop_list_get_next (CRPropList *a_this) ;
|
||||
|
||||
CRPropList * cr_prop_list_get_prev (CRPropList *a_this) ;
|
||||
|
||||
enum CRStatus cr_prop_list_set_decl (CRPropList *a_this,
|
||||
CRDeclaration *a_decl);
|
||||
|
||||
enum CRStatus cr_prop_list_get_decl (CRPropList const *a_this,
|
||||
CRDeclaration **a_decl) ;
|
||||
|
||||
CRPropList * cr_prop_list_unlink (CRPropList *a_this,
|
||||
CRPropList *a_pair) ;
|
||||
|
||||
void cr_prop_list_destroy (CRPropList *a_this) ;
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /*__CR_PROP_LIST_H__*/
|
167
src/st/croco/cr-pseudo.c
Normal file
167
src/st/croco/cr-pseudo.c
Normal file
@ -0,0 +1,167 @@
|
||||
/* -*- Mode: C; indent-tabs-mode:nil; c-basic-offset: 8-*- */
|
||||
|
||||
/*
|
||||
* This file is part of The Croco Library
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of version 2.1 of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*
|
||||
* Author: Dodji Seketeli
|
||||
* See COPYRIGHTS file for copyright information.
|
||||
*/
|
||||
|
||||
#include "cr-pseudo.h"
|
||||
|
||||
/**
|
||||
*@CRPseudo:
|
||||
*The definition of the #CRPseudo class.
|
||||
*/
|
||||
|
||||
/**
|
||||
* cr_pseudo_new:
|
||||
*Constructor of the #CRPseudo class.
|
||||
*
|
||||
*Returns the newly build instance.
|
||||
*/
|
||||
CRPseudo *
|
||||
cr_pseudo_new (void)
|
||||
{
|
||||
CRPseudo *result = NULL;
|
||||
|
||||
result = g_malloc0 (sizeof (CRPseudo));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_pseudo_to_string:
|
||||
* @a_this: the current instance of #CRPseud.
|
||||
*
|
||||
* Returns the serialized pseudo. Caller must free the returned
|
||||
* string using g_free().
|
||||
*/
|
||||
guchar *
|
||||
cr_pseudo_to_string (CRPseudo const * a_this)
|
||||
{
|
||||
guchar *result = NULL;
|
||||
GString *str_buf = NULL;
|
||||
|
||||
g_return_val_if_fail (a_this, NULL);
|
||||
|
||||
str_buf = g_string_new (NULL);
|
||||
|
||||
if (a_this->type == IDENT_PSEUDO) {
|
||||
guchar *name = NULL;
|
||||
|
||||
if (a_this->name == NULL) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
name = (guchar *) g_strndup (a_this->name->stryng->str,
|
||||
a_this->name->stryng->len);
|
||||
|
||||
if (name) {
|
||||
g_string_append (str_buf, (const gchar *) name);
|
||||
g_free (name);
|
||||
name = NULL;
|
||||
}
|
||||
} else if (a_this->type == FUNCTION_PSEUDO) {
|
||||
guchar *name = NULL,
|
||||
*arg = NULL;
|
||||
|
||||
if (a_this->name == NULL)
|
||||
goto error;
|
||||
|
||||
name = (guchar *) g_strndup (a_this->name->stryng->str,
|
||||
a_this->name->stryng->len);
|
||||
|
||||
if (a_this->extra) {
|
||||
arg = (guchar *) g_strndup (a_this->extra->stryng->str,
|
||||
a_this->extra->stryng->len);
|
||||
}
|
||||
|
||||
if (name) {
|
||||
g_string_append_printf (str_buf, "%s(", name);
|
||||
g_free (name);
|
||||
name = NULL;
|
||||
|
||||
if (arg) {
|
||||
g_string_append (str_buf, (const gchar *) arg);
|
||||
g_free (arg);
|
||||
arg = NULL;
|
||||
}
|
||||
|
||||
g_string_append_c (str_buf, ')');
|
||||
}
|
||||
}
|
||||
|
||||
if (str_buf) {
|
||||
result = (guchar *) str_buf->str;
|
||||
g_string_free (str_buf, FALSE);
|
||||
str_buf = NULL;
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
error:
|
||||
g_string_free (str_buf, TRUE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_pseudo_dump:
|
||||
*@a_this: the current instance of pseudo
|
||||
*@a_fp: the destination file pointer.
|
||||
*
|
||||
*Dumps the pseudo to a file.
|
||||
*
|
||||
*/
|
||||
void
|
||||
cr_pseudo_dump (CRPseudo const * a_this, FILE * a_fp)
|
||||
{
|
||||
guchar *tmp_str = NULL;
|
||||
|
||||
if (a_this) {
|
||||
tmp_str = cr_pseudo_to_string (a_this);
|
||||
if (tmp_str) {
|
||||
fprintf (a_fp, "%s", tmp_str);
|
||||
g_free (tmp_str);
|
||||
tmp_str = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_pseudo_destroy:
|
||||
*@a_this: the current instance to destroy.
|
||||
*
|
||||
*destructor of the #CRPseudo class.
|
||||
*/
|
||||
void
|
||||
cr_pseudo_destroy (CRPseudo * a_this)
|
||||
{
|
||||
g_return_if_fail (a_this);
|
||||
|
||||
if (a_this->name) {
|
||||
cr_string_destroy (a_this->name);
|
||||
a_this->name = NULL;
|
||||
}
|
||||
|
||||
if (a_this->extra) {
|
||||
cr_string_destroy (a_this->extra);
|
||||
a_this->extra = NULL;
|
||||
}
|
||||
|
||||
g_free (a_this);
|
||||
}
|
64
src/st/croco/cr-pseudo.h
Normal file
64
src/st/croco/cr-pseudo.h
Normal file
@ -0,0 +1,64 @@
|
||||
/* -*- Mode: C; indent-tabs-mode:nil; c-basic-offset: 8-*- */
|
||||
|
||||
/*
|
||||
* This file is part of The Croco Library
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of version 2.1 of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*
|
||||
* See COPYRIGHTS file for copyright information
|
||||
*/
|
||||
|
||||
#ifndef __CR_PSEUDO_H__
|
||||
#define __CR_PSEUDO_H__
|
||||
|
||||
#include <stdio.h>
|
||||
#include <glib.h>
|
||||
#include "cr-attr-sel.h"
|
||||
#include "cr-parsing-location.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
enum CRPseudoType
|
||||
{
|
||||
IDENT_PSEUDO = 0,
|
||||
FUNCTION_PSEUDO
|
||||
} ;
|
||||
|
||||
typedef struct _CRPseudo CRPseudo ;
|
||||
|
||||
/**
|
||||
*The CRPseudo Class.
|
||||
*Abstract a "pseudo" as defined by the css2 spec
|
||||
*in appendix D.1 .
|
||||
*/
|
||||
struct _CRPseudo
|
||||
{
|
||||
enum CRPseudoType type ;
|
||||
CRString *name ;
|
||||
CRString *extra ;
|
||||
CRParsingLocation location ;
|
||||
} ;
|
||||
|
||||
CRPseudo * cr_pseudo_new (void) ;
|
||||
|
||||
guchar * cr_pseudo_to_string (CRPseudo const *a_this) ;
|
||||
|
||||
void cr_pseudo_dump (CRPseudo const *a_this, FILE *a_fp) ;
|
||||
|
||||
void cr_pseudo_destroy (CRPseudo *a_this) ;
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /*__CR_PSEUDO_H__*/
|
687
src/st/croco/cr-rgb.c
Normal file
687
src/st/croco/cr-rgb.c
Normal file
@ -0,0 +1,687 @@
|
||||
/* -*- Mode: C; indent-tabs-mode:nil; c-basic-offset: 8-*- */
|
||||
|
||||
/*
|
||||
* This file is part of The Croco Library
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of version 2.1 of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*
|
||||
* Author: Dodji Seketeli
|
||||
* See COPYRIGHTS file for copyrights information.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "cr-rgb.h"
|
||||
#include "cr-term.h"
|
||||
#include "cr-parser.h"
|
||||
|
||||
static const CRRgb gv_standard_colors[] = {
|
||||
{(const guchar*)"aliceblue", 240, 248, 255, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"antiquewhite", 250, 235, 215, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"aqua", 0, 255, 255, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"aquamarine", 127, 255, 212, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"azure", 240, 255, 255, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"beige", 245, 245, 220, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"bisque", 255, 228, 196, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"black", 0, 0, 0, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"blanchedalmond", 255, 235, 205, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"blue", 0, 0, 255, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"blueviolet", 138, 43, 226, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"brown", 165, 42, 42, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"burlywood", 222, 184, 135, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"cadetblue", 95, 158, 160, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"chartreuse", 127, 255, 0, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"chocolate", 210, 105, 30, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"coral", 255, 127, 80, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"cornflowerblue", 100, 149, 237, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"cornsilk", 255, 248, 220, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"crimson", 220, 20, 60, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"cyan", 0, 255, 255, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"darkblue", 0, 0, 139, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"darkcyan", 0, 139, 139, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"darkgoldenrod", 184, 134, 11, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"darkgray", 169, 169, 169, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"darkgreen", 0, 100, 0, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"darkgrey", 169, 169, 169, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"darkkhaki", 189, 183, 107, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"darkmagenta", 139, 0, 139, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"darkolivegreen", 85, 107, 47, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"darkorange", 255, 140, 0, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"darkorchid", 153, 50, 204, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"darkred", 139, 0, 0, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"darksalmon", 233, 150, 122, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"darkseagreen", 143, 188, 143, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"darkslateblue", 72, 61, 139, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"darkslategray", 47, 79, 79, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"darkslategrey", 47, 79, 79, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"darkturquoise", 0, 206, 209, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"darkviolet", 148, 0, 211, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"deeppink", 255, 20, 147, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"deepskyblue", 0, 191, 255, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"dimgray", 105, 105, 105, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"dimgrey", 105, 105, 105, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"dodgerblue", 30, 144, 255, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"firebrick", 178, 34, 34, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"floralwhite", 255, 250, 240, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"forestgreen", 34, 139, 34, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"fuchsia", 255, 0, 255, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"gainsboro", 220, 220, 220, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"ghostwhite", 248, 248, 255, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"gold", 255, 215, 0, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"goldenrod", 218, 165, 32, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"gray", 128, 128, 128, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"green", 0, 128, 0, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"greenyellow", 173, 255, 47, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"grey", 128, 128, 128, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"honeydew", 240, 255, 240, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"hotpink", 255, 105, 180, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"indianred", 205, 92, 92, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"indigo", 75, 0, 130, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"ivory", 255, 255, 240, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"khaki", 240, 230, 140, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"lavender", 230, 230, 250, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"lavenderblush", 255, 240, 245, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"lawngreen", 124, 252, 0, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"lemonchiffon", 255, 250, 205, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"lightblue", 173, 216, 230, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"lightcoral", 240, 128, 128, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"lightcyan", 224, 255, 255, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"lightgoldenrodyellow", 250, 250, 210, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"lightgray", 211, 211, 211, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"lightgreen", 144, 238, 144, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"lightgrey", 211, 211, 211, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"lightpink", 255, 182, 193, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"lightsalmon", 255, 160, 122, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"lightseagreen", 32, 178, 170, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"lightskyblue", 135, 206, 250, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"lightslategray", 119, 136, 153, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"lightslategrey", 119, 136, 153, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"lightsteelblue", 176, 196, 222, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"lightyellow", 255, 255, 224, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"lime", 0, 255, 0, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"limegreen", 50, 205, 50, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"linen", 250, 240, 230, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"magenta", 255, 0, 255, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"maroon", 128, 0, 0, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"mediumaquamarine", 102, 205, 170, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"mediumblue", 0, 0, 205, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"mediumorchid", 186, 85, 211, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"mediumpurple", 147, 112, 219, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"mediumseagreen", 60, 179, 113, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"mediumslateblue", 123, 104, 238, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"mediumspringgreen", 0, 250, 154, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"mediumturquoise", 72, 209, 204, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"mediumvioletred", 199, 21, 133, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"midnightblue", 25, 25, 112, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"mintcream", 245, 255, 250, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"mistyrose", 255, 228, 225, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"moccasin", 255, 228, 181, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"navajowhite", 255, 222, 173, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"navy", 0, 0, 128, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"oldlace", 253, 245, 230, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"olive", 128, 128, 0, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"olivedrab", 107, 142, 35, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"orange", 255, 165, 0, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"orangered", 255, 69, 0, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"orchid", 218, 112, 214, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"palegoldenrod", 238, 232, 170, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"palegreen", 152, 251, 152, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"paleturquoise", 175, 238, 238, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"palevioletred", 219, 112, 147, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"papayawhip", 255, 239, 213, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"peachpuff", 255, 218, 185, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"peru", 205, 133, 63, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"pink", 255, 192, 203, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"plum", 221, 160, 221, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"powderblue", 176, 224, 230, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"purple", 128, 0, 128, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"red", 255, 0, 0, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"rosybrown", 188, 143, 143, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"royalblue", 65, 105, 225, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"saddlebrown", 139, 69, 19, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"salmon", 250, 128, 114, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"sandybrown", 244, 164, 96, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"seagreen", 46, 139, 87, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"seashell", 255, 245, 238, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"sienna", 160, 82, 45, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"silver", 192, 192, 192, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"skyblue", 135, 206, 235, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"slateblue", 106, 90, 205, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"slategray", 112, 128, 144, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"slategrey", 112, 128, 144, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"snow", 255, 250, 250, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"springgreen", 0, 255, 127, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"steelblue", 70, 130, 180, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"tan", 210, 180, 140, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"teal", 0, 128, 128, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"thistle", 216, 191, 216, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"tomato", 255, 99, 71, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"transparent", 255, 255, 255, FALSE, FALSE, TRUE, {0,0,0}},
|
||||
{(const guchar*)"turquoise", 64, 224, 208, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"violet", 238, 130, 238, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"wheat", 245, 222, 179, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"white", 255, 255, 255, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"whitesmoke", 245, 245, 245, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"yellow", 255, 255, 0, FALSE, FALSE, FALSE, {0,0,0}},
|
||||
{(const guchar*)"yellowgreen", 154, 205, 50, FALSE, FALSE, FALSE, {0,0,0}}
|
||||
};
|
||||
|
||||
/**
|
||||
* cr_rgb_new:
|
||||
*
|
||||
*The default constructor of #CRRgb.
|
||||
*
|
||||
*Returns the newly built instance of #CRRgb
|
||||
*/
|
||||
CRRgb *
|
||||
cr_rgb_new (void)
|
||||
{
|
||||
CRRgb *result = NULL;
|
||||
|
||||
result = g_try_malloc (sizeof (CRRgb));
|
||||
|
||||
if (result == NULL) {
|
||||
cr_utils_trace_info ("No more memory");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset (result, 0, sizeof (CRRgb));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_rgb_new_with_vals:
|
||||
*@a_red: the red component of the color.
|
||||
*@a_green: the green component of the color.
|
||||
*@a_blue: the blue component of the color.
|
||||
*@a_unit: the unit of the rgb values.
|
||||
*(either percentage or integer values)
|
||||
*
|
||||
*A constructor of #CRRgb.
|
||||
*
|
||||
*Returns the newly built instance of #CRRgb.
|
||||
*/
|
||||
CRRgb *
|
||||
cr_rgb_new_with_vals (gulong a_red, gulong a_green,
|
||||
gulong a_blue, gboolean a_is_percentage)
|
||||
{
|
||||
CRRgb *result = NULL;
|
||||
|
||||
result = cr_rgb_new ();
|
||||
|
||||
g_return_val_if_fail (result, NULL);
|
||||
|
||||
result->red = a_red;
|
||||
result->green = a_green;
|
||||
result->blue = a_blue;
|
||||
result->is_percentage = a_is_percentage;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_rgb_to_string:
|
||||
*@a_this: the instance of #CRRgb to serialize.
|
||||
*
|
||||
*Serializes the rgb into a zero terminated string.
|
||||
*
|
||||
*Returns the zero terminated string containing the serialized
|
||||
*rgb. MUST BE FREED by the caller using g_free().
|
||||
*/
|
||||
guchar *
|
||||
cr_rgb_to_string (CRRgb const * a_this)
|
||||
{
|
||||
guchar *result = NULL;
|
||||
GString *str_buf = NULL;
|
||||
|
||||
str_buf = g_string_new (NULL);
|
||||
g_return_val_if_fail (str_buf, NULL);
|
||||
|
||||
if (a_this->is_percentage == 1) {
|
||||
g_string_append_printf (str_buf, "%ld", a_this->red);
|
||||
|
||||
g_string_append (str_buf, "%, ");
|
||||
|
||||
g_string_append_printf (str_buf, "%ld", a_this->green);
|
||||
g_string_append (str_buf, "%, ");
|
||||
|
||||
g_string_append_printf (str_buf, "%ld", a_this->blue);
|
||||
g_string_append_c (str_buf, '%');
|
||||
} else {
|
||||
g_string_append_printf (str_buf, "%ld", a_this->red);
|
||||
g_string_append (str_buf, ", ");
|
||||
|
||||
g_string_append_printf (str_buf, "%ld", a_this->green);
|
||||
g_string_append (str_buf, ", ");
|
||||
|
||||
g_string_append_printf (str_buf, "%ld", a_this->blue);
|
||||
}
|
||||
|
||||
if (str_buf) {
|
||||
result = (guchar *) str_buf->str;
|
||||
g_string_free (str_buf, FALSE);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_rgb_dump:
|
||||
*@a_this: the "this pointer" of
|
||||
*the current instance of #CRRgb.
|
||||
*@a_fp: the destination file pointer.
|
||||
*
|
||||
*Dumps the current instance of #CRRgb
|
||||
*to a file.
|
||||
*/
|
||||
void
|
||||
cr_rgb_dump (CRRgb const * a_this, FILE * a_fp)
|
||||
{
|
||||
guchar *str = NULL;
|
||||
|
||||
g_return_if_fail (a_this);
|
||||
|
||||
str = cr_rgb_to_string (a_this);
|
||||
|
||||
if (str) {
|
||||
fprintf (a_fp, "%s", str);
|
||||
g_free (str);
|
||||
str = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_rgb_compute_from_percentage:
|
||||
*@a_this: the current instance of #CRRgb
|
||||
*
|
||||
*If the rgb values are expressed in percentage,
|
||||
*compute their real value.
|
||||
*
|
||||
*Returns CR_OK upon successful completion, an error code otherwise.
|
||||
*/
|
||||
enum CRStatus
|
||||
cr_rgb_compute_from_percentage (CRRgb * a_this)
|
||||
{
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
|
||||
|
||||
if (a_this->is_percentage == FALSE)
|
||||
return CR_OK;
|
||||
a_this->red = a_this->red * 255 / 100;
|
||||
a_this->green = a_this->green * 255 / 100;
|
||||
a_this->blue = a_this->blue * 255 / 100;
|
||||
a_this->is_percentage = FALSE;
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_rgb_set:
|
||||
*@a_this: the current instance of #CRRgb.
|
||||
*@a_red: the red value.
|
||||
*@a_green: the green value.
|
||||
*@a_blue: the blue value.
|
||||
*
|
||||
*Sets rgb values to the RGB.
|
||||
*
|
||||
*Returns CR_OK upon successful completion, an error code
|
||||
*otherwise.
|
||||
*/
|
||||
enum CRStatus
|
||||
cr_rgb_set (CRRgb * a_this, gulong a_red,
|
||||
gulong a_green, gulong a_blue, gboolean a_is_percentage)
|
||||
{
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
|
||||
if (a_is_percentage != FALSE) {
|
||||
g_return_val_if_fail (a_red <= 100
|
||||
&& a_green <= 100
|
||||
&& a_blue <= 100, CR_BAD_PARAM_ERROR);
|
||||
}
|
||||
|
||||
a_this->is_percentage = a_is_percentage;
|
||||
|
||||
a_this->red = a_red;
|
||||
a_this->green = a_green;
|
||||
a_this->blue = a_blue;
|
||||
a_this->inherit = FALSE ;
|
||||
a_this->is_transparent = FALSE ;
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_rgb_set_to_inherit:
|
||||
*@a_this: the current instance of #CRRgb
|
||||
*
|
||||
*sets the value of the rgb to inherit.
|
||||
*Look at the css spec from chapter 6.1 to 6.2 to understand
|
||||
*the meaning of "inherit".
|
||||
*
|
||||
* Returns CR_OK upon succesful completion, an error code otherwise.
|
||||
*/
|
||||
enum CRStatus
|
||||
cr_rgb_set_to_inherit (CRRgb *a_this, gboolean a_inherit)
|
||||
{
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
|
||||
|
||||
a_this->inherit = a_inherit ;
|
||||
|
||||
return CR_OK ;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_rgb_is_set_to_inherit:
|
||||
*
|
||||
* @a_this: the current instance of #CRRgb.
|
||||
*
|
||||
* Returns TRUE if the rgb is set to the value "inherit", FALSE otherwise.
|
||||
*/
|
||||
gboolean
|
||||
cr_rgb_is_set_to_inherit (CRRgb const *a_this)
|
||||
{
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
|
||||
|
||||
return a_this->inherit ;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_rgb_is_set_to_transparent:
|
||||
*@a_this: the current instance of
|
||||
*#CRRgb
|
||||
*
|
||||
*Tests if the the rgb is set to the
|
||||
*value "transparent" or not.
|
||||
*
|
||||
*Returns TRUE if the rgb has been set to
|
||||
*transparent, FALSE otherwise.
|
||||
*/
|
||||
gboolean
|
||||
cr_rgb_is_set_to_transparent (CRRgb const *a_this)
|
||||
{
|
||||
g_return_val_if_fail (a_this, FALSE) ;
|
||||
return a_this->is_transparent ;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* cr_rgb_set_to_transparent:
|
||||
*@a_this: the current instance of #CRRgb
|
||||
*@a_is_transparent: set to transparent or not.
|
||||
*
|
||||
*Sets the rgb to the "transparent" value (or not)
|
||||
*Returns CR_OK upon successfull completion, an error code otherwise.
|
||||
*/
|
||||
enum CRStatus
|
||||
cr_rgb_set_to_transparent (CRRgb *a_this,
|
||||
gboolean a_is_transparent)
|
||||
{
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
|
||||
a_this->is_transparent = a_is_transparent ;
|
||||
return CR_OK ;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_rgb_set_from_rgb:
|
||||
*@a_this: the current instance of #CRRgb.
|
||||
*@a_rgb: the rgb to "copy"
|
||||
*
|
||||
*Sets the rgb from an other one.
|
||||
*
|
||||
*Returns CR_OK upon successful completion, an error code otherwise.
|
||||
*/
|
||||
enum CRStatus
|
||||
cr_rgb_set_from_rgb (CRRgb * a_this, CRRgb const * a_rgb)
|
||||
{
|
||||
g_return_val_if_fail (a_this && a_rgb, CR_BAD_PARAM_ERROR);
|
||||
|
||||
cr_rgb_copy (a_this, a_rgb) ;
|
||||
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
static int
|
||||
cr_rgb_color_name_compare (const void *a,
|
||||
const void *b)
|
||||
{
|
||||
const char *a_color_name = a;
|
||||
const CRRgb *rgb = b;
|
||||
|
||||
return g_ascii_strcasecmp (a_color_name, (const char *) rgb->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_rgb_set_from_name:
|
||||
* @a_this: the current instance of #CRRgb
|
||||
* @a_color_name: the color name
|
||||
*
|
||||
* Returns CR_OK upon successful completion, an error code otherwise.
|
||||
*/
|
||||
enum CRStatus
|
||||
cr_rgb_set_from_name (CRRgb * a_this, const guchar * a_color_name)
|
||||
{
|
||||
enum CRStatus status = CR_OK;
|
||||
CRRgb *result;
|
||||
|
||||
g_return_val_if_fail (a_this && a_color_name, CR_BAD_PARAM_ERROR);
|
||||
|
||||
result = bsearch (a_color_name,
|
||||
gv_standard_colors,
|
||||
G_N_ELEMENTS (gv_standard_colors),
|
||||
sizeof (gv_standard_colors[0]),
|
||||
cr_rgb_color_name_compare);
|
||||
if (result != NULL)
|
||||
cr_rgb_set_from_rgb (a_this, result);
|
||||
else
|
||||
status = CR_UNKNOWN_TYPE_ERROR;
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_rgb_set_from_hex_str:
|
||||
* @a_this: the current instance of #CRRgb
|
||||
* @a_hex: the hexadecimal value to set.
|
||||
*
|
||||
* Returns CR_OK upon successful completion.
|
||||
*/
|
||||
enum CRStatus
|
||||
cr_rgb_set_from_hex_str (CRRgb * a_this, const guchar * a_hex)
|
||||
{
|
||||
enum CRStatus status = CR_OK;
|
||||
gulong i = 0;
|
||||
guchar colors[3] = { 0 };
|
||||
|
||||
g_return_val_if_fail (a_this && a_hex, CR_BAD_PARAM_ERROR);
|
||||
|
||||
if (strlen ((const char *) a_hex) == 3) {
|
||||
for (i = 0; i < 3; i++) {
|
||||
if (a_hex[i] >= '0' && a_hex[i] <= '9') {
|
||||
colors[i] = a_hex[i] - '0';
|
||||
colors[i] = (colors[i] << 4) | colors[i];
|
||||
} else if (a_hex[i] >= 'a' && a_hex[i] <= 'z') {
|
||||
colors[i] = 10 + a_hex[i] - 'a';
|
||||
colors[i] = (colors[i] << 4) | colors[i];
|
||||
} else if (a_hex[i] >= 'A' && a_hex[i] <= 'Z') {
|
||||
colors[i] = 10 + a_hex[i] - 'A';
|
||||
colors[i] = (colors[i] << 4) | colors[i];
|
||||
} else {
|
||||
status = CR_UNKNOWN_TYPE_ERROR;
|
||||
}
|
||||
}
|
||||
} else if (strlen ((const char *) a_hex) == 6) {
|
||||
for (i = 0; i < 6; i++) {
|
||||
if (a_hex[i] >= '0' && a_hex[i] <= '9') {
|
||||
colors[i / 2] <<= 4;
|
||||
colors[i / 2] |= a_hex[i] - '0';
|
||||
status = CR_OK;
|
||||
} else if (a_hex[i] >= 'a' && a_hex[i] <= 'z') {
|
||||
colors[i / 2] <<= 4;
|
||||
colors[i / 2] |= 10 + a_hex[i] - 'a';
|
||||
status = CR_OK;
|
||||
} else if (a_hex[i] >= 'A' && a_hex[i] <= 'Z') {
|
||||
colors[i / 2] <<= 4;
|
||||
colors[i / 2] |= 10 + a_hex[i] - 'A';
|
||||
status = CR_OK;
|
||||
} else {
|
||||
status = CR_UNKNOWN_TYPE_ERROR;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
status = CR_UNKNOWN_TYPE_ERROR;
|
||||
}
|
||||
|
||||
if (status == CR_OK) {
|
||||
status = cr_rgb_set (a_this, colors[0],
|
||||
colors[1], colors[2], FALSE);
|
||||
cr_rgb_set_to_transparent (a_this, FALSE) ;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_rgb_set_from_term:
|
||||
*@a_this: the instance of #CRRgb to set
|
||||
*@a_value: the terminal from which to set
|
||||
*
|
||||
*Set the rgb from a terminal symbol
|
||||
*
|
||||
* Returns CR_OK upon successful completion, an error code otherwise.
|
||||
*/
|
||||
enum CRStatus
|
||||
cr_rgb_set_from_term (CRRgb *a_this, const struct _CRTerm *a_value)
|
||||
{
|
||||
enum CRStatus status = CR_OK ;
|
||||
g_return_val_if_fail (a_this && a_value,
|
||||
CR_BAD_PARAM_ERROR) ;
|
||||
|
||||
switch(a_value->type) {
|
||||
case TERM_RGB:
|
||||
if (a_value->content.rgb) {
|
||||
cr_rgb_set_from_rgb
|
||||
(a_this, a_value->content.rgb) ;
|
||||
}
|
||||
break ;
|
||||
case TERM_IDENT:
|
||||
if (a_value->content.str
|
||||
&& a_value->content.str->stryng
|
||||
&& a_value->content.str->stryng->str) {
|
||||
if (!strncmp ("inherit",
|
||||
a_value->content.str->stryng->str,
|
||||
sizeof ("inherit")-1)) {
|
||||
a_this->inherit = TRUE;
|
||||
a_this->is_transparent = FALSE ;
|
||||
} else {
|
||||
status = cr_rgb_set_from_name
|
||||
(a_this,
|
||||
(const guchar *) a_value->content.str->stryng->str) ;
|
||||
}
|
||||
} else {
|
||||
cr_utils_trace_info
|
||||
("a_value has NULL string value") ;
|
||||
}
|
||||
break ;
|
||||
case TERM_HASH:
|
||||
if (a_value->content.str
|
||||
&& a_value->content.str->stryng
|
||||
&& a_value->content.str->stryng->str) {
|
||||
status = cr_rgb_set_from_hex_str
|
||||
(a_this,
|
||||
(const guchar *) a_value->content.str->stryng->str) ;
|
||||
} else {
|
||||
cr_utils_trace_info
|
||||
("a_value has NULL string value") ;
|
||||
}
|
||||
break ;
|
||||
default:
|
||||
status = CR_UNKNOWN_TYPE_ERROR ;
|
||||
}
|
||||
return status ;
|
||||
}
|
||||
|
||||
enum CRStatus
|
||||
cr_rgb_copy (CRRgb *a_dest, CRRgb const *a_src)
|
||||
{
|
||||
g_return_val_if_fail (a_dest && a_src,
|
||||
CR_BAD_PARAM_ERROR) ;
|
||||
|
||||
memcpy (a_dest, a_src, sizeof (CRRgb)) ;
|
||||
return CR_OK ;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_rgb_destroy:
|
||||
*@a_this: the "this pointer" of the
|
||||
*current instance of #CRRgb.
|
||||
*
|
||||
*Destructor of #CRRgb.
|
||||
*/
|
||||
void
|
||||
cr_rgb_destroy (CRRgb * a_this)
|
||||
{
|
||||
g_return_if_fail (a_this);
|
||||
g_free (a_this);
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_rgb_parse_from_buf:
|
||||
*@a_str: a string that contains a color description
|
||||
*@a_enc: the encoding of a_str
|
||||
*
|
||||
*Parses a text buffer that contains a rgb color
|
||||
*
|
||||
*Returns the parsed color, or NULL in case of error
|
||||
*/
|
||||
CRRgb *
|
||||
cr_rgb_parse_from_buf (const guchar *a_str,
|
||||
enum CREncoding a_enc)
|
||||
{
|
||||
enum CRStatus status = CR_OK ;
|
||||
CRTerm *value = NULL ;
|
||||
CRParser * parser = NULL;
|
||||
CRRgb *result = NULL;
|
||||
|
||||
g_return_val_if_fail (a_str, NULL);
|
||||
|
||||
parser = cr_parser_new_from_buf ((guchar *) a_str, strlen ((const char *) a_str), a_enc, FALSE);
|
||||
|
||||
g_return_val_if_fail (parser, NULL);
|
||||
|
||||
status = cr_parser_try_to_skip_spaces_and_comments (parser) ;
|
||||
if (status != CR_OK)
|
||||
goto cleanup;
|
||||
|
||||
status = cr_parser_parse_term (parser, &value);
|
||||
if (status != CR_OK)
|
||||
goto cleanup;
|
||||
|
||||
result = cr_rgb_new ();
|
||||
if (!result)
|
||||
goto cleanup;
|
||||
|
||||
status = cr_rgb_set_from_term (result, value);
|
||||
|
||||
cleanup:
|
||||
if (parser) {
|
||||
cr_parser_destroy (parser);
|
||||
parser = NULL;
|
||||
}
|
||||
if (value) {
|
||||
cr_term_destroy(value);
|
||||
value = NULL;
|
||||
}
|
||||
return result ;
|
||||
}
|
||||
|
94
src/st/croco/cr-rgb.h
Normal file
94
src/st/croco/cr-rgb.h
Normal file
@ -0,0 +1,94 @@
|
||||
/* -*- Mode: C; indent-tabs-mode:nil; c-basic-offset: 8-*- */
|
||||
|
||||
/*
|
||||
* This file is part of The Croco Library
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of version 2.1 of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*
|
||||
* see COPYRIGHTS file for copyright information.
|
||||
*/
|
||||
|
||||
#ifndef __CR_RGB_H__
|
||||
#define __CR_RGB_H__
|
||||
|
||||
#include <stdio.h>
|
||||
#include <glib.h>
|
||||
#include "cr-utils.h"
|
||||
#include "cr-parsing-location.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
||||
typedef struct _CRRgb CRRgb ;
|
||||
struct _CRRgb
|
||||
{
|
||||
/*
|
||||
*the unit of the rgb.
|
||||
*Either NO_UNIT (integer) or
|
||||
*UNIT_PERCENTAGE (percentage).
|
||||
*/
|
||||
const guchar *name ;
|
||||
glong red ;
|
||||
glong green ;
|
||||
glong blue ;
|
||||
gboolean is_percentage ;
|
||||
gboolean inherit ;
|
||||
gboolean is_transparent ;
|
||||
CRParsingLocation location ;
|
||||
} ;
|
||||
|
||||
CRRgb * cr_rgb_new (void) ;
|
||||
|
||||
CRRgb * cr_rgb_new_with_vals (gulong a_red, gulong a_green,
|
||||
gulong a_blue, gboolean a_is_percentage) ;
|
||||
|
||||
CRRgb *cr_rgb_parse_from_buf(const guchar *a_str,
|
||||
enum CREncoding a_enc);
|
||||
|
||||
enum CRStatus cr_rgb_compute_from_percentage (CRRgb *a_this) ;
|
||||
|
||||
enum CRStatus cr_rgb_set (CRRgb *a_this, gulong a_red,
|
||||
gulong a_green, gulong a_blue,
|
||||
gboolean a_is_percentage) ;
|
||||
|
||||
enum CRStatus cr_rgb_copy (CRRgb *a_dest, CRRgb const *a_src) ;
|
||||
|
||||
enum CRStatus cr_rgb_set_to_inherit (CRRgb *a_this, gboolean a_inherit) ;
|
||||
|
||||
gboolean cr_rgb_is_set_to_inherit (CRRgb const *a_this) ;
|
||||
|
||||
gboolean cr_rgb_is_set_to_transparent (CRRgb const *a_this) ;
|
||||
|
||||
enum CRStatus cr_rgb_set_to_transparent (CRRgb *a_this,
|
||||
gboolean a_is_transparent) ;
|
||||
enum CRStatus cr_rgb_set_from_rgb (CRRgb *a_this, CRRgb const *a_rgb) ;
|
||||
|
||||
enum CRStatus cr_rgb_set_from_name (CRRgb *a_this, const guchar *a_color_name) ;
|
||||
|
||||
enum CRStatus cr_rgb_set_from_hex_str (CRRgb *a_this, const guchar * a_hex_value) ;
|
||||
|
||||
struct _CRTerm;
|
||||
|
||||
enum CRStatus cr_rgb_set_from_term (CRRgb *a_this, const struct _CRTerm *a_value);
|
||||
|
||||
guchar * cr_rgb_to_string (CRRgb const *a_this) ;
|
||||
|
||||
void cr_rgb_dump (CRRgb const *a_this, FILE *a_fp) ;
|
||||
|
||||
void cr_rgb_destroy (CRRgb *a_this) ;
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /*__CR_RGB_H__*/
|
306
src/st/croco/cr-selector.c
Normal file
306
src/st/croco/cr-selector.c
Normal file
@ -0,0 +1,306 @@
|
||||
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
|
||||
|
||||
/*
|
||||
* This file is part of The Croco Library
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of version 2.1 of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*
|
||||
* See COPYRIGHTS file for copyright information.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "cr-selector.h"
|
||||
#include "cr-parser.h"
|
||||
|
||||
/**
|
||||
* cr_selector_new:
|
||||
*
|
||||
*@a_simple_sel: the initial simple selector list
|
||||
*of the current instance of #CRSelector.
|
||||
*
|
||||
*Creates a new instance of #CRSelector.
|
||||
*
|
||||
*Returns the newly built instance of #CRSelector, or
|
||||
*NULL in case of failure.
|
||||
*/
|
||||
CRSelector *
|
||||
cr_selector_new (CRSimpleSel * a_simple_sel)
|
||||
{
|
||||
CRSelector *result = NULL;
|
||||
|
||||
result = g_try_malloc (sizeof (CRSelector));
|
||||
if (!result) {
|
||||
cr_utils_trace_info ("Out of memory");
|
||||
return NULL;
|
||||
}
|
||||
memset (result, 0, sizeof (CRSelector));
|
||||
result->simple_sel = a_simple_sel;
|
||||
return result;
|
||||
}
|
||||
|
||||
CRSelector *
|
||||
cr_selector_parse_from_buf (const guchar * a_char_buf, enum CREncoding a_enc)
|
||||
{
|
||||
CRParser *parser = NULL;
|
||||
|
||||
g_return_val_if_fail (a_char_buf, NULL);
|
||||
|
||||
parser = cr_parser_new_from_buf ((guchar*)a_char_buf, strlen ((const char *) a_char_buf),
|
||||
a_enc, FALSE);
|
||||
g_return_val_if_fail (parser, NULL);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_selector_append:
|
||||
*
|
||||
*@a_this: the current instance of #CRSelector.
|
||||
*@a_new: the instance of #CRSelector to be appended.
|
||||
*
|
||||
*Appends a new instance of #CRSelector to the current selector list.
|
||||
*
|
||||
*Returns the new list.
|
||||
*/
|
||||
CRSelector *
|
||||
cr_selector_append (CRSelector * a_this, CRSelector * a_new)
|
||||
{
|
||||
CRSelector *cur = NULL;
|
||||
|
||||
if (!a_this) {
|
||||
return a_new;
|
||||
}
|
||||
|
||||
/*walk forward the list headed by a_this to get the list tail */
|
||||
for (cur = a_this; cur && cur->next; cur = cur->next) ;
|
||||
|
||||
cur->next = a_new;
|
||||
a_new->prev = cur;
|
||||
|
||||
return a_this;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_selector_prepend:
|
||||
*
|
||||
*@a_this: the current instance of #CRSelector list.
|
||||
*@a_new: the instance of #CRSelector.
|
||||
*
|
||||
*Prepends an element to the #CRSelector list.
|
||||
*
|
||||
*Returns the new list.
|
||||
*/
|
||||
CRSelector *
|
||||
cr_selector_prepend (CRSelector * a_this, CRSelector * a_new)
|
||||
{
|
||||
CRSelector *cur = NULL;
|
||||
|
||||
a_new->next = a_this;
|
||||
a_this->prev = a_new;
|
||||
|
||||
for (cur = a_new; cur && cur->prev; cur = cur->prev) ;
|
||||
|
||||
return cur;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_selector_append_simple_sel:
|
||||
*
|
||||
*@a_this: the current instance of #CRSelector.
|
||||
*@a_simple_sel: the simple selector to append.
|
||||
*
|
||||
*append a simple selector to the current #CRSelector list.
|
||||
*
|
||||
*Returns the new list or NULL in case of failure.
|
||||
*/
|
||||
CRSelector *
|
||||
cr_selector_append_simple_sel (CRSelector * a_this,
|
||||
CRSimpleSel * a_simple_sel)
|
||||
{
|
||||
CRSelector *selector = NULL;
|
||||
|
||||
selector = cr_selector_new (a_simple_sel);
|
||||
g_return_val_if_fail (selector, NULL);
|
||||
|
||||
return cr_selector_append (a_this, selector);
|
||||
}
|
||||
|
||||
guchar *
|
||||
cr_selector_to_string (CRSelector const * a_this)
|
||||
{
|
||||
guchar *result = NULL;
|
||||
GString *str_buf = NULL;
|
||||
|
||||
str_buf = g_string_new (NULL);
|
||||
g_return_val_if_fail (str_buf, NULL);
|
||||
|
||||
if (a_this) {
|
||||
CRSelector const *cur = NULL;
|
||||
|
||||
for (cur = a_this; cur; cur = cur->next) {
|
||||
if (cur->simple_sel) {
|
||||
guchar *tmp_str = NULL;
|
||||
|
||||
tmp_str = cr_simple_sel_to_string
|
||||
(cur->simple_sel);
|
||||
|
||||
if (tmp_str) {
|
||||
if (cur->prev)
|
||||
g_string_append (str_buf,
|
||||
", ");
|
||||
|
||||
g_string_append (str_buf, (const gchar *) tmp_str);
|
||||
|
||||
g_free (tmp_str);
|
||||
tmp_str = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (str_buf) {
|
||||
result = (guchar *) str_buf->str;
|
||||
g_string_free (str_buf, FALSE);
|
||||
str_buf = NULL;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_selector_dump:
|
||||
*
|
||||
*@a_this: the current instance of #CRSelector.
|
||||
*@a_fp: the destination file.
|
||||
*
|
||||
*Serializes the current instance of #CRSelector to a file.
|
||||
*/
|
||||
void
|
||||
cr_selector_dump (CRSelector const * a_this, FILE * a_fp)
|
||||
{
|
||||
guchar *tmp_buf = NULL;
|
||||
|
||||
if (a_this) {
|
||||
tmp_buf = cr_selector_to_string (a_this);
|
||||
if (tmp_buf) {
|
||||
fprintf (a_fp, "%s", tmp_buf);
|
||||
g_free (tmp_buf);
|
||||
tmp_buf = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_selector_ref:
|
||||
*
|
||||
*@a_this: the current instance of #CRSelector.
|
||||
*
|
||||
*Increments the ref count of the current instance
|
||||
*of #CRSelector.
|
||||
*/
|
||||
void
|
||||
cr_selector_ref (CRSelector * a_this)
|
||||
{
|
||||
g_return_if_fail (a_this);
|
||||
|
||||
a_this->ref_count++;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_selector_unref:
|
||||
*
|
||||
*@a_this: the current instance of #CRSelector.
|
||||
*
|
||||
*Decrements the ref count of the current instance of
|
||||
*#CRSelector.
|
||||
*If the ref count reaches zero, the current instance of
|
||||
*#CRSelector is destroyed.
|
||||
*
|
||||
*Returns TRUE if this function destroyed the current instance
|
||||
*of #CRSelector, FALSE otherwise.
|
||||
*/
|
||||
gboolean
|
||||
cr_selector_unref (CRSelector * a_this)
|
||||
{
|
||||
g_return_val_if_fail (a_this, FALSE);
|
||||
|
||||
if (a_this->ref_count) {
|
||||
a_this->ref_count--;
|
||||
}
|
||||
|
||||
if (a_this->ref_count == 0) {
|
||||
cr_selector_destroy (a_this);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_selector_destroy:
|
||||
*
|
||||
*@a_this: the current instance of #CRSelector.
|
||||
*
|
||||
*Destroys the selector list.
|
||||
*/
|
||||
void
|
||||
cr_selector_destroy (CRSelector * a_this)
|
||||
{
|
||||
CRSelector *cur = NULL;
|
||||
|
||||
g_return_if_fail (a_this);
|
||||
|
||||
/*
|
||||
*go and get the list tail. In the same time, free
|
||||
*all the simple selectors contained in the list.
|
||||
*/
|
||||
for (cur = a_this; cur && cur->next; cur = cur->next) {
|
||||
if (cur->simple_sel) {
|
||||
cr_simple_sel_destroy (cur->simple_sel);
|
||||
cur->simple_sel = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (cur) {
|
||||
if (cur->simple_sel) {
|
||||
cr_simple_sel_destroy (cur->simple_sel);
|
||||
cur->simple_sel = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/*in case the list has only one element */
|
||||
if (cur && !cur->prev) {
|
||||
g_free (cur);
|
||||
return;
|
||||
}
|
||||
|
||||
/*walk backward the list and free each "next element" */
|
||||
for (cur = cur->prev; cur && cur->prev; cur = cur->prev) {
|
||||
if (cur->next) {
|
||||
g_free (cur->next);
|
||||
cur->next = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (!cur)
|
||||
return;
|
||||
|
||||
if (cur->next) {
|
||||
g_free (cur->next);
|
||||
cur->next = NULL;
|
||||
}
|
||||
|
||||
g_free (cur);
|
||||
}
|
95
src/st/croco/cr-selector.h
Normal file
95
src/st/croco/cr-selector.h
Normal file
@ -0,0 +1,95 @@
|
||||
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
|
||||
|
||||
/*
|
||||
* This file is part of The Croco Library
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of version 2.1 of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*
|
||||
*
|
||||
* Author: Dodji Seketeli
|
||||
* See COPYRIGHTS file for copyright information.
|
||||
*/
|
||||
|
||||
#ifndef __CR_SELECTOR_H__
|
||||
#define __CR_SELECTOR_H__
|
||||
|
||||
#include <stdio.h>
|
||||
#include "cr-utils.h"
|
||||
#include "cr-simple-sel.h"
|
||||
#include "cr-parsing-location.h"
|
||||
|
||||
/**
|
||||
*@file
|
||||
*The declaration file of the #CRSelector file.
|
||||
*/
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _CRSelector CRSelector ;
|
||||
|
||||
/**
|
||||
*Abstracts a CSS2 selector as defined in the right part
|
||||
*of the 'ruleset" production in the appendix D.1 of the
|
||||
*css2 spec.
|
||||
*It is actually the abstraction of a comma separated list
|
||||
*of simple selectors list.
|
||||
*In a css2 file, a selector is a list of simple selectors
|
||||
*separated by a comma.
|
||||
*e.g: sel0, sel1, sel2 ...
|
||||
*Each seln is a simple selector
|
||||
*/
|
||||
struct _CRSelector
|
||||
{
|
||||
/**
|
||||
*A Selection expression.
|
||||
*It is a list of basic selectors.
|
||||
*Each basic selector can be either an element
|
||||
*selector, an id selector, a class selector, an
|
||||
*attribute selector, an universal selector etc ...
|
||||
*/
|
||||
CRSimpleSel *simple_sel ;
|
||||
|
||||
/**The next selector list element*/
|
||||
CRSelector *next ;
|
||||
CRSelector *prev ;
|
||||
CRParsingLocation location ;
|
||||
glong ref_count ;
|
||||
};
|
||||
|
||||
CRSelector* cr_selector_new (CRSimpleSel *a_sel_expr) ;
|
||||
|
||||
CRSelector * cr_selector_parse_from_buf (const guchar * a_char_buf,
|
||||
enum CREncoding a_enc) ;
|
||||
|
||||
CRSelector* cr_selector_append (CRSelector *a_this, CRSelector *a_new) ;
|
||||
|
||||
CRSelector* cr_selector_append_simple_sel (CRSelector *a_this,
|
||||
CRSimpleSel *a_simple_sel) ;
|
||||
|
||||
CRSelector* cr_selector_prepend (CRSelector *a_this, CRSelector *a_new) ;
|
||||
|
||||
guchar * cr_selector_to_string (CRSelector const *a_this) ;
|
||||
|
||||
void cr_selector_dump (CRSelector const *a_this, FILE *a_fp) ;
|
||||
|
||||
void cr_selector_ref (CRSelector *a_this) ;
|
||||
|
||||
gboolean cr_selector_unref (CRSelector *a_this) ;
|
||||
|
||||
void cr_selector_destroy (CRSelector *a_this) ;
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /*__CR_SELECTOR_H__*/
|
325
src/st/croco/cr-simple-sel.c
Normal file
325
src/st/croco/cr-simple-sel.c
Normal file
@ -0,0 +1,325 @@
|
||||
/* -*- Mode: C; indent-tabs-mode:nil; c-basic-offset: 8-*- */
|
||||
|
||||
/*
|
||||
* This file is part of The Croco Library
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of version 2.1 of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*
|
||||
* Author: Dodji Seketeli
|
||||
* See COPYRIGHTS file for copyright information.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <glib.h>
|
||||
#include "cr-simple-sel.h"
|
||||
|
||||
/**
|
||||
* cr_simple_sel_new:
|
||||
*
|
||||
*The constructor of #CRSimpleSel.
|
||||
*
|
||||
*Returns the new instance of #CRSimpleSel.
|
||||
*/
|
||||
CRSimpleSel *
|
||||
cr_simple_sel_new (void)
|
||||
{
|
||||
CRSimpleSel *result = NULL;
|
||||
|
||||
result = g_try_malloc (sizeof (CRSimpleSel));
|
||||
if (!result) {
|
||||
cr_utils_trace_info ("Out of memory");
|
||||
return NULL;
|
||||
}
|
||||
memset (result, 0, sizeof (CRSimpleSel));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_simple_sel_append_simple_sel:
|
||||
*
|
||||
*Appends a simpe selector to the current list of simple selector.
|
||||
*
|
||||
*@a_this: the this pointer of the current instance of #CRSimpleSel.
|
||||
*@a_sel: the simple selector to append.
|
||||
*
|
||||
*Returns: the new list upon successfull completion, an error code otherwise.
|
||||
*/
|
||||
CRSimpleSel *
|
||||
cr_simple_sel_append_simple_sel (CRSimpleSel * a_this, CRSimpleSel * a_sel)
|
||||
{
|
||||
CRSimpleSel *cur = NULL;
|
||||
|
||||
g_return_val_if_fail (a_sel, NULL);
|
||||
|
||||
if (a_this == NULL)
|
||||
return a_sel;
|
||||
|
||||
for (cur = a_this; cur->next; cur = cur->next) ;
|
||||
|
||||
cur->next = a_sel;
|
||||
a_sel->prev = cur;
|
||||
|
||||
return a_this;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_simple_sel_prepend_simple_sel:
|
||||
*
|
||||
*@a_this: the this pointer of the current instance of #CRSimpleSel.
|
||||
*@a_sel: the simple selector to prepend.
|
||||
*
|
||||
*Prepends a simple selector to the current list of simple selectors.
|
||||
*
|
||||
*Returns the new list upon successfull completion, an error code otherwise.
|
||||
*/
|
||||
CRSimpleSel *
|
||||
cr_simple_sel_prepend_simple_sel (CRSimpleSel * a_this, CRSimpleSel * a_sel)
|
||||
{
|
||||
g_return_val_if_fail (a_sel, NULL);
|
||||
|
||||
if (a_this == NULL)
|
||||
return a_sel;
|
||||
|
||||
a_sel->next = a_this;
|
||||
a_this->prev = a_sel;
|
||||
|
||||
return a_sel;
|
||||
}
|
||||
|
||||
guchar *
|
||||
cr_simple_sel_to_string (CRSimpleSel const * a_this)
|
||||
{
|
||||
GString *str_buf = NULL;
|
||||
guchar *result = NULL;
|
||||
|
||||
CRSimpleSel const *cur = NULL;
|
||||
|
||||
g_return_val_if_fail (a_this, NULL);
|
||||
|
||||
str_buf = g_string_new (NULL);
|
||||
for (cur = a_this; cur; cur = cur->next) {
|
||||
if (cur->name) {
|
||||
guchar *str = (guchar *) g_strndup (cur->name->stryng->str,
|
||||
cur->name->stryng->len);
|
||||
|
||||
if (str) {
|
||||
switch (cur->combinator) {
|
||||
case COMB_WS:
|
||||
g_string_append (str_buf, " ");
|
||||
break;
|
||||
|
||||
case COMB_PLUS:
|
||||
g_string_append (str_buf, "+");
|
||||
break;
|
||||
|
||||
case COMB_GT:
|
||||
g_string_append (str_buf, ">");
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
g_string_append (str_buf, (const gchar *) str);
|
||||
g_free (str);
|
||||
str = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (cur->add_sel) {
|
||||
guchar *tmp_str = NULL;
|
||||
|
||||
tmp_str = cr_additional_sel_to_string (cur->add_sel);
|
||||
if (tmp_str) {
|
||||
g_string_append (str_buf, (const gchar *) tmp_str);
|
||||
g_free (tmp_str);
|
||||
tmp_str = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (str_buf) {
|
||||
result = (guchar *) str_buf->str;
|
||||
g_string_free (str_buf, FALSE);
|
||||
str_buf = NULL;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
guchar *
|
||||
cr_simple_sel_one_to_string (CRSimpleSel const * a_this)
|
||||
{
|
||||
GString *str_buf = NULL;
|
||||
guchar *result = NULL;
|
||||
|
||||
g_return_val_if_fail (a_this, NULL);
|
||||
|
||||
str_buf = g_string_new (NULL);
|
||||
if (a_this->name) {
|
||||
guchar *str = (guchar *) g_strndup (a_this->name->stryng->str,
|
||||
a_this->name->stryng->len);
|
||||
|
||||
if (str) {
|
||||
g_string_append_printf (str_buf, "%s", str);
|
||||
g_free (str);
|
||||
str = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (a_this->add_sel) {
|
||||
guchar *tmp_str = NULL;
|
||||
|
||||
tmp_str = cr_additional_sel_to_string (a_this->add_sel);
|
||||
if (tmp_str) {
|
||||
g_string_append_printf
|
||||
(str_buf, "%s", tmp_str);
|
||||
g_free (tmp_str);
|
||||
tmp_str = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (str_buf) {
|
||||
result = (guchar *) str_buf->str;
|
||||
g_string_free (str_buf, FALSE);
|
||||
str_buf = NULL;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_simple_sel_dump:
|
||||
*@a_this: the current instance of #CRSimpleSel.
|
||||
*@a_fp: the destination file pointer.
|
||||
*
|
||||
*Dumps the selector to a file.
|
||||
*TODO: add the support of unicode in the dump.
|
||||
*
|
||||
*Returns CR_OK upon successfull completion, an error code
|
||||
*otherwise.
|
||||
*/
|
||||
enum CRStatus
|
||||
cr_simple_sel_dump (CRSimpleSel const * a_this, FILE * a_fp)
|
||||
{
|
||||
guchar *tmp_str = NULL;
|
||||
|
||||
g_return_val_if_fail (a_fp, CR_BAD_PARAM_ERROR);
|
||||
|
||||
if (a_this) {
|
||||
tmp_str = cr_simple_sel_to_string (a_this);
|
||||
if (tmp_str) {
|
||||
fprintf (a_fp, "%s", tmp_str);
|
||||
g_free (tmp_str);
|
||||
tmp_str = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_simple_sel_compute_specificity:
|
||||
*
|
||||
*@a_this: the current instance of #CRSimpleSel
|
||||
*
|
||||
*Computes the selector (combinator separated list of simple selectors)
|
||||
*as defined in the css2 spec in chapter 6.4.3
|
||||
*
|
||||
*Returns CR_OK upon successfull completion, an error code otherwise.
|
||||
*/
|
||||
enum CRStatus
|
||||
cr_simple_sel_compute_specificity (CRSimpleSel * a_this)
|
||||
{
|
||||
CRAdditionalSel const *cur_add_sel = NULL;
|
||||
CRSimpleSel const *cur_sel = NULL;
|
||||
gulong a = 0,
|
||||
b = 0,
|
||||
c = 0;
|
||||
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
|
||||
|
||||
for (cur_sel = a_this; cur_sel; cur_sel = cur_sel->next) {
|
||||
if (cur_sel->type_mask & TYPE_SELECTOR) {
|
||||
c++; /*hmmh, is this a new language ? */
|
||||
} else if (!cur_sel->name
|
||||
|| !cur_sel->name->stryng
|
||||
|| !cur_sel->name->stryng->str) {
|
||||
if (cur_sel->add_sel->type ==
|
||||
PSEUDO_CLASS_ADD_SELECTOR) {
|
||||
/*
|
||||
*this is a pseudo element, and
|
||||
*the spec says, "ignore pseudo elements".
|
||||
*/
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
for (cur_add_sel = cur_sel->add_sel;
|
||||
cur_add_sel; cur_add_sel = cur_add_sel->next) {
|
||||
switch (cur_add_sel->type) {
|
||||
case ID_ADD_SELECTOR:
|
||||
a++;
|
||||
break;
|
||||
|
||||
case NO_ADD_SELECTOR:
|
||||
continue;
|
||||
|
||||
default:
|
||||
b++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*we suppose a, b and c have 1 to 3 digits */
|
||||
a_this->specificity = a * 1000000 + b * 1000 + c;
|
||||
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* cr_simple_sel_destroy:
|
||||
*
|
||||
*@a_this: the this pointer of the current instance of #CRSimpleSel.
|
||||
*
|
||||
*The destructor of the current instance of
|
||||
*#CRSimpleSel.
|
||||
*/
|
||||
void
|
||||
cr_simple_sel_destroy (CRSimpleSel * a_this)
|
||||
{
|
||||
g_return_if_fail (a_this);
|
||||
|
||||
if (a_this->name) {
|
||||
cr_string_destroy (a_this->name);
|
||||
a_this->name = NULL;
|
||||
}
|
||||
|
||||
if (a_this->add_sel) {
|
||||
cr_additional_sel_destroy (a_this->add_sel);
|
||||
a_this->add_sel = NULL;
|
||||
}
|
||||
|
||||
if (a_this->next) {
|
||||
cr_simple_sel_destroy (a_this->next);
|
||||
}
|
||||
|
||||
if (a_this) {
|
||||
g_free (a_this);
|
||||
}
|
||||
}
|
130
src/st/croco/cr-simple-sel.h
Normal file
130
src/st/croco/cr-simple-sel.h
Normal file
@ -0,0 +1,130 @@
|
||||
/* -*- Mode: C; indent-tabs-mode:nil; c-basic-offset: 8-*- */
|
||||
|
||||
/*
|
||||
* This file is part of The Croco Library
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of version 2.1 of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*
|
||||
* Author: Dodji Seketeli
|
||||
* See COPYRIGHTS file for copyright information.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __CR_SEL_H__
|
||||
#define __CR_SEL_H__
|
||||
|
||||
#include <stdio.h>
|
||||
#include <glib.h>
|
||||
#include "cr-additional-sel.h"
|
||||
#include "cr-parsing-location.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/**
|
||||
*@file
|
||||
*the declaration of the #CRSimpleSel class.
|
||||
*
|
||||
*/
|
||||
enum Combinator
|
||||
{
|
||||
NO_COMBINATOR,
|
||||
COMB_WS,/*whitespace: descendent*/
|
||||
COMB_PLUS,/*'+': preceded by*/
|
||||
COMB_GT/*greater than ('>'): child*/
|
||||
} ;
|
||||
|
||||
enum SimpleSelectorType
|
||||
{
|
||||
NO_SELECTOR_TYPE = 0,
|
||||
UNIVERSAL_SELECTOR = 1,
|
||||
TYPE_SELECTOR = 1 << 1
|
||||
} ;
|
||||
|
||||
typedef struct _CRSimpleSel CRSimpleSel ;
|
||||
|
||||
/**
|
||||
*The abstraction of a css2 simple selection list
|
||||
*as defined by the right part of the "selector" production in the
|
||||
*appendix D.1 of the css2 spec.
|
||||
*It is basically a list of simple selector, each
|
||||
*simple selector being separated by a combinator.
|
||||
*
|
||||
*In the libcroco's implementation, each simple selector
|
||||
*is made of at most two parts:
|
||||
*
|
||||
*1/An element name or 'type selector' (which can hold a '*' and
|
||||
*then been called 'universal selector')
|
||||
*
|
||||
*2/An additional selector that "specializes" the preceding type or
|
||||
*universal selector. The additionnal selector can be either
|
||||
*an id selector, or a class selector, or an attribute selector.
|
||||
*/
|
||||
struct _CRSimpleSel
|
||||
{
|
||||
enum SimpleSelectorType type_mask ;
|
||||
gboolean is_case_sentive ;
|
||||
CRString * name ;
|
||||
/**
|
||||
*The combinator that separates
|
||||
*this simple selector from the previous
|
||||
*one.
|
||||
*/
|
||||
enum Combinator combinator ;
|
||||
|
||||
/**
|
||||
*The additional selector list of the
|
||||
*current simple selector.
|
||||
*An additional selector may
|
||||
*be a class selector, an id selector,
|
||||
*or an attribute selector.
|
||||
*Note that this field is a linked list.
|
||||
*/
|
||||
CRAdditionalSel *add_sel ;
|
||||
|
||||
/*
|
||||
*the specificity as specified by
|
||||
*chapter 6.4.3 of the spec.
|
||||
*/
|
||||
gulong specificity ;
|
||||
|
||||
CRSimpleSel *next ;
|
||||
CRSimpleSel *prev ;
|
||||
CRParsingLocation location ;
|
||||
} ;
|
||||
|
||||
CRSimpleSel * cr_simple_sel_new (void) ;
|
||||
|
||||
CRSimpleSel * cr_simple_sel_append_simple_sel (CRSimpleSel *a_this,
|
||||
CRSimpleSel *a_sel) ;
|
||||
|
||||
CRSimpleSel * cr_simple_sel_prepend_simple_sel (CRSimpleSel *a_this,
|
||||
CRSimpleSel *a_sel) ;
|
||||
|
||||
guchar * cr_simple_sel_to_string (CRSimpleSel const *a_this) ;
|
||||
|
||||
guchar * cr_simple_sel_one_to_string (CRSimpleSel const * a_this) ;
|
||||
|
||||
enum CRStatus cr_simple_sel_dump (CRSimpleSel const *a_this, FILE *a_fp) ;
|
||||
|
||||
enum CRStatus cr_simple_sel_dump_attr_sel_list (CRSimpleSel const *a_this) ;
|
||||
|
||||
enum CRStatus cr_simple_sel_compute_specificity (CRSimpleSel *a_this) ;
|
||||
|
||||
void cr_simple_sel_destroy (CRSimpleSel *a_this) ;
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
||||
#endif /*__CR_SIMPLE_SEL_H__*/
|
2794
src/st/croco/cr-statement.c
Normal file
2794
src/st/croco/cr-statement.c
Normal file
File diff suppressed because it is too large
Load Diff
440
src/st/croco/cr-statement.h
Normal file
440
src/st/croco/cr-statement.h
Normal file
@ -0,0 +1,440 @@
|
||||
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
|
||||
|
||||
/*
|
||||
* This file is part of The Croco Library
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of version 2.1 of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*
|
||||
* Author: Dodji Seketeli
|
||||
* See COPYRIGHTS file for copyright information.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "cr-utils.h"
|
||||
#include "cr-term.h"
|
||||
#include "cr-selector.h"
|
||||
#include "cr-declaration.h"
|
||||
|
||||
#ifndef __CR_STATEMENT_H__
|
||||
#define __CR_STATEMENT_H__
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/**
|
||||
*@file
|
||||
*Declaration of the #CRStatement class.
|
||||
*/
|
||||
|
||||
/*
|
||||
*forward declaration of CRStyleSheet which is defined in
|
||||
*cr-stylesheet.h
|
||||
*/
|
||||
|
||||
struct _CRStatement ;
|
||||
|
||||
/*
|
||||
*typedef struct _CRStatement CRStatement ;
|
||||
*this is forward declared in
|
||||
*cr-declaration.h already.
|
||||
*/
|
||||
|
||||
struct _CRAtMediaRule ;
|
||||
typedef struct _CRAtMediaRule CRAtMediaRule ;
|
||||
|
||||
typedef struct _CRRuleSet CRRuleSet ;
|
||||
|
||||
/**
|
||||
*The abstraction of a css ruleset.
|
||||
*A ruleset is made of a list of selectors,
|
||||
*followed by a list of declarations.
|
||||
*/
|
||||
struct _CRRuleSet
|
||||
{
|
||||
/**A list of instances of #CRSimpeSel*/
|
||||
CRSelector *sel_list ;
|
||||
|
||||
/**A list of instances of #CRDeclaration*/
|
||||
CRDeclaration *decl_list ;
|
||||
|
||||
/**
|
||||
*The parent media rule, or NULL if
|
||||
*no parent media rule exists.
|
||||
*/
|
||||
CRStatement *parent_media_rule ;
|
||||
} ;
|
||||
|
||||
/*
|
||||
*a forward declaration of CRStylesheet.
|
||||
*CRStylesheet is actually declared in
|
||||
*cr-stylesheet.h
|
||||
*/
|
||||
struct _CRStyleSheet ;
|
||||
typedef struct _CRStyleSheet CRStyleSheet;
|
||||
|
||||
|
||||
/**The \@import rule abstraction.*/
|
||||
typedef struct _CRAtImportRule CRAtImportRule ;
|
||||
struct _CRAtImportRule
|
||||
{
|
||||
/**the url of the import rule*/
|
||||
CRString *url ;
|
||||
|
||||
GList *media_list ;
|
||||
|
||||
/**
|
||||
*the stylesheet fetched from the url, if any.
|
||||
*this is not "owned" by #CRAtImportRule which means
|
||||
*it is not destroyed by the destructor of #CRAtImportRule.
|
||||
*/
|
||||
CRStyleSheet * sheet;
|
||||
};
|
||||
|
||||
|
||||
/**abstraction of an \@media rule*/
|
||||
struct _CRAtMediaRule
|
||||
{
|
||||
GList *media_list ;
|
||||
CRStatement *rulesets ;
|
||||
} ;
|
||||
|
||||
|
||||
typedef struct _CRAtPageRule CRAtPageRule ;
|
||||
/**The \@page rule abstraction*/
|
||||
struct _CRAtPageRule
|
||||
{
|
||||
/**a list of instances of #CRDeclaration*/
|
||||
CRDeclaration *decl_list ;
|
||||
|
||||
/**page selector. Is a pseudo selector*/
|
||||
CRString *name ;
|
||||
CRString *pseudo ;
|
||||
} ;
|
||||
|
||||
/**The \@charset rule abstraction*/
|
||||
typedef struct _CRAtCharsetRule CRAtCharsetRule ;
|
||||
struct _CRAtCharsetRule
|
||||
{
|
||||
CRString * charset ;
|
||||
};
|
||||
|
||||
/**The abstaction of the \@font-face rule.*/
|
||||
typedef struct _CRAtFontFaceRule CRAtFontFaceRule ;
|
||||
struct _CRAtFontFaceRule
|
||||
{
|
||||
/*a list of instanaces of #CRDeclaration*/
|
||||
CRDeclaration *decl_list ;
|
||||
} ;
|
||||
|
||||
|
||||
/**
|
||||
*The possible types of css2 statements.
|
||||
*/
|
||||
enum CRStatementType
|
||||
{
|
||||
/**
|
||||
*A generic css at-rule
|
||||
*each unknown at-rule will
|
||||
*be of this type.
|
||||
*/
|
||||
|
||||
/**A css at-rule*/
|
||||
AT_RULE_STMT = 0,
|
||||
|
||||
/*A css ruleset*/
|
||||
RULESET_STMT,
|
||||
|
||||
/**A css2 import rule*/
|
||||
AT_IMPORT_RULE_STMT,
|
||||
|
||||
/**A css2 media rule*/
|
||||
AT_MEDIA_RULE_STMT,
|
||||
|
||||
/**A css2 page rule*/
|
||||
AT_PAGE_RULE_STMT,
|
||||
|
||||
/**A css2 charset rule*/
|
||||
AT_CHARSET_RULE_STMT,
|
||||
|
||||
/**A css2 font face rule*/
|
||||
AT_FONT_FACE_RULE_STMT
|
||||
} ;
|
||||
|
||||
|
||||
/**
|
||||
*The abstraction of css statement as defined
|
||||
*in the chapter 4 and appendix D.1 of the css2 spec.
|
||||
*A statement is actually a double chained list of
|
||||
*statements.A statement can be a ruleset, an \@import
|
||||
*rule, an \@page rule etc ...
|
||||
*/
|
||||
struct _CRStatement
|
||||
{
|
||||
/**
|
||||
*The type of the statement.
|
||||
*/
|
||||
enum CRStatementType type ;
|
||||
|
||||
union
|
||||
{
|
||||
CRRuleSet *ruleset ;
|
||||
CRAtImportRule *import_rule ;
|
||||
CRAtMediaRule *media_rule ;
|
||||
CRAtPageRule *page_rule ;
|
||||
CRAtCharsetRule *charset_rule ;
|
||||
CRAtFontFaceRule *font_face_rule ;
|
||||
} kind ;
|
||||
|
||||
/*
|
||||
*the specificity of the selector
|
||||
*that matched this statement.
|
||||
*This is only used by the cascading
|
||||
*order determination algorithm.
|
||||
*/
|
||||
gulong specificity ;
|
||||
|
||||
/*
|
||||
*the style sheet that contains
|
||||
*this css statement.
|
||||
*/
|
||||
CRStyleSheet *parent_sheet ;
|
||||
CRStatement *next ;
|
||||
CRStatement *prev ;
|
||||
|
||||
CRParsingLocation location ;
|
||||
|
||||
/**
|
||||
*a custom pointer useable by
|
||||
*applications that use libcroco.
|
||||
*libcroco itself will never modify
|
||||
*this pointer.
|
||||
*/
|
||||
gpointer app_data ;
|
||||
|
||||
/**
|
||||
*a custom pointer used
|
||||
*by the upper layers of libcroco.
|
||||
*application should never use this
|
||||
*pointer.
|
||||
*/
|
||||
gpointer croco_data ;
|
||||
|
||||
} ;
|
||||
|
||||
|
||||
gboolean
|
||||
cr_statement_does_buf_parses_against_core (const guchar *a_buf,
|
||||
enum CREncoding a_encoding) ;
|
||||
CRStatement *
|
||||
cr_statement_parse_from_buf (const guchar *a_buf,
|
||||
enum CREncoding a_encoding) ;
|
||||
CRStatement*
|
||||
cr_statement_new_ruleset (CRStyleSheet *a_sheet,
|
||||
CRSelector *a_sel_list,
|
||||
CRDeclaration *a_decl_list,
|
||||
CRStatement *a_media_rule) ;
|
||||
CRStatement *
|
||||
cr_statement_ruleset_parse_from_buf (const guchar * a_buf,
|
||||
enum CREncoding a_enc) ;
|
||||
|
||||
CRStatement*
|
||||
cr_statement_new_at_import_rule (CRStyleSheet *a_container_sheet,
|
||||
CRString *a_url,
|
||||
GList *a_media_list,
|
||||
CRStyleSheet *a_imported_sheet) ;
|
||||
|
||||
CRStatement *
|
||||
cr_statement_at_import_rule_parse_from_buf (const guchar * a_buf,
|
||||
enum CREncoding a_encoding) ;
|
||||
|
||||
CRStatement *
|
||||
cr_statement_new_at_media_rule (CRStyleSheet *a_sheet,
|
||||
CRStatement *a_ruleset,
|
||||
GList *a_media) ;
|
||||
CRStatement *
|
||||
cr_statement_at_media_rule_parse_from_buf (const guchar *a_buf,
|
||||
enum CREncoding a_enc) ;
|
||||
|
||||
CRStatement *
|
||||
cr_statement_new_at_charset_rule (CRStyleSheet *a_sheet,
|
||||
CRString *a_charset) ;
|
||||
CRStatement *
|
||||
cr_statement_at_charset_rule_parse_from_buf (const guchar *a_buf,
|
||||
enum CREncoding a_encoding);
|
||||
|
||||
|
||||
CRStatement *
|
||||
cr_statement_new_at_font_face_rule (CRStyleSheet *a_sheet,
|
||||
CRDeclaration *a_font_decls) ;
|
||||
CRStatement *
|
||||
cr_statement_font_face_rule_parse_from_buf (const guchar *a_buf,
|
||||
enum CREncoding a_encoding) ;
|
||||
|
||||
CRStatement *
|
||||
cr_statement_new_at_page_rule (CRStyleSheet *a_sheet,
|
||||
CRDeclaration *a_decl_list,
|
||||
CRString *a_name,
|
||||
CRString *a_pseudo) ;
|
||||
CRStatement *
|
||||
cr_statement_at_page_rule_parse_from_buf (const guchar *a_buf,
|
||||
enum CREncoding a_encoding) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_statement_set_parent_sheet (CRStatement *a_this,
|
||||
CRStyleSheet *a_sheet) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_statement_get_parent_sheet (CRStatement *a_this,
|
||||
CRStyleSheet **a_sheet) ;
|
||||
|
||||
CRStatement *
|
||||
cr_statement_append (CRStatement *a_this,
|
||||
CRStatement *a_new) ;
|
||||
|
||||
CRStatement*
|
||||
cr_statement_prepend (CRStatement *a_this,
|
||||
CRStatement *a_new) ;
|
||||
|
||||
CRStatement *
|
||||
cr_statement_unlink (CRStatement *a_stmt) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_statement_ruleset_set_sel_list (CRStatement *a_this,
|
||||
CRSelector *a_sel_list) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_statement_ruleset_get_sel_list (CRStatement const *a_this,
|
||||
CRSelector **a_list) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_statement_ruleset_set_decl_list (CRStatement *a_this,
|
||||
CRDeclaration *a_list) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_statement_ruleset_get_declarations (CRStatement *a_this,
|
||||
CRDeclaration **a_decl_list) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_statement_ruleset_append_decl2 (CRStatement *a_this,
|
||||
CRString *a_prop, CRTerm *a_value) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_statement_ruleset_append_decl (CRStatement *a_this,
|
||||
CRDeclaration *a_decl) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_statement_at_import_rule_set_imported_sheet (CRStatement *a_this,
|
||||
CRStyleSheet *a_sheet) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_statement_at_import_rule_get_imported_sheet (CRStatement *a_this,
|
||||
CRStyleSheet **a_sheet) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_statement_at_import_rule_set_url (CRStatement *a_this,
|
||||
CRString *a_url) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_statement_at_import_rule_get_url (CRStatement const *a_this,
|
||||
CRString **a_url) ;
|
||||
|
||||
gint
|
||||
cr_statement_at_media_nr_rules (CRStatement const *a_this) ;
|
||||
|
||||
CRStatement *
|
||||
cr_statement_at_media_get_from_list (CRStatement *a_this, int itemnr) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_statement_at_page_rule_set_sel (CRStatement *a_this,
|
||||
CRSelector *a_sel) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_statement_at_page_rule_get_sel (CRStatement const *a_this,
|
||||
CRSelector **a_sel) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_statement_at_page_rule_set_declarations (CRStatement *a_this,
|
||||
CRDeclaration *a_decl_list) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_statement_at_page_rule_get_declarations (CRStatement *a_this,
|
||||
CRDeclaration **a_decl_list) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_statement_at_charset_rule_set_charset (CRStatement *a_this,
|
||||
CRString *a_charset) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_statement_at_charset_rule_get_charset (CRStatement const *a_this,
|
||||
CRString **a_charset) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_statement_at_font_face_rule_set_decls (CRStatement *a_this,
|
||||
CRDeclaration *a_decls) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_statement_at_font_face_rule_get_decls (CRStatement *a_this,
|
||||
CRDeclaration **a_decls) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_statement_at_font_face_rule_add_decl (CRStatement *a_this,
|
||||
CRString *a_prop,
|
||||
CRTerm *a_value) ;
|
||||
|
||||
gchar *
|
||||
cr_statement_to_string (CRStatement const * a_this, gulong a_indent) ;
|
||||
|
||||
gchar*
|
||||
cr_statement_list_to_string (CRStatement const *a_this, gulong a_indent) ;
|
||||
|
||||
void
|
||||
cr_statement_dump (CRStatement const *a_this, FILE *a_fp, gulong a_indent) ;
|
||||
|
||||
void
|
||||
cr_statement_dump_ruleset (CRStatement const * a_this, FILE * a_fp,
|
||||
glong a_indent) ;
|
||||
|
||||
void
|
||||
cr_statement_dump_font_face_rule (CRStatement const * a_this,
|
||||
FILE * a_fp,
|
||||
glong a_indent) ;
|
||||
|
||||
void
|
||||
cr_statement_dump_page (CRStatement const * a_this, FILE * a_fp,
|
||||
gulong a_indent) ;
|
||||
|
||||
|
||||
void
|
||||
cr_statement_dump_media_rule (CRStatement const * a_this,
|
||||
FILE * a_fp,
|
||||
gulong a_indent) ;
|
||||
|
||||
void
|
||||
cr_statement_dump_import_rule (CRStatement const * a_this, FILE * a_fp,
|
||||
gulong a_indent) ;
|
||||
void
|
||||
cr_statement_dump_charset (CRStatement const * a_this, FILE * a_fp,
|
||||
gulong a_indent) ;
|
||||
gint
|
||||
cr_statement_nr_rules (CRStatement const *a_this) ;
|
||||
|
||||
CRStatement *
|
||||
cr_statement_get_from_list (CRStatement *a_this, int itemnr) ;
|
||||
|
||||
void
|
||||
cr_statement_destroy (CRStatement *a_this) ;
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /*__CR_STATEMENT_H__*/
|
168
src/st/croco/cr-string.c
Normal file
168
src/st/croco/cr-string.c
Normal file
@ -0,0 +1,168 @@
|
||||
/* -*- Mode: C; indent-tabs-mode:nil; c-basic-offset: 8-*- */
|
||||
|
||||
/*
|
||||
* This file is part of The Croco Library
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of version 2.1 of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*
|
||||
* Author: Dodji Seketeli.
|
||||
* See COPYRIGHTS file for copyright information.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "cr-string.h"
|
||||
|
||||
/**
|
||||
*Instanciates a #CRString
|
||||
*@return the newly instanciated #CRString
|
||||
*Must be freed with cr_string_destroy().
|
||||
*/
|
||||
CRString *
|
||||
cr_string_new (void)
|
||||
{
|
||||
CRString *result = NULL ;
|
||||
|
||||
result = g_try_malloc (sizeof (CRString)) ;
|
||||
if (!result) {
|
||||
cr_utils_trace_info ("Out of memory") ;
|
||||
return NULL ;
|
||||
}
|
||||
memset (result, 0, sizeof (CRString)) ;
|
||||
result->stryng = g_string_new (NULL) ;
|
||||
return result ;
|
||||
}
|
||||
|
||||
/**
|
||||
*Instanciate a string and initialise it to
|
||||
*a_string.
|
||||
*@param a_string the initial string
|
||||
*@return the newly instanciated string.
|
||||
*/
|
||||
CRString *
|
||||
cr_string_new_from_string (const gchar * a_string)
|
||||
{
|
||||
CRString *result = NULL ;
|
||||
|
||||
result = cr_string_new () ;
|
||||
if (!result) {
|
||||
cr_utils_trace_info ("Out of memory") ;
|
||||
return NULL ;
|
||||
}
|
||||
if (a_string)
|
||||
g_string_append (result->stryng, a_string) ;
|
||||
return result ;
|
||||
}
|
||||
|
||||
/**
|
||||
*Instanciates a #CRString from an instance of GString.
|
||||
*@param a_string the input string that will be copied into
|
||||
*the newly instanciated #CRString
|
||||
*@return the newly instanciated #CRString.
|
||||
*/
|
||||
CRString *
|
||||
cr_string_new_from_gstring (GString const *a_string)
|
||||
{
|
||||
CRString *result = NULL ;
|
||||
|
||||
result = cr_string_new () ;
|
||||
if (!result) {
|
||||
cr_utils_trace_info ("Out of memory") ;
|
||||
return NULL ;
|
||||
}
|
||||
if (a_string) {
|
||||
g_string_append_len (result->stryng,
|
||||
a_string->str,
|
||||
a_string->len);
|
||||
|
||||
}
|
||||
return result ;
|
||||
}
|
||||
|
||||
CRString *
|
||||
cr_string_dup (CRString const *a_this)
|
||||
{
|
||||
CRString *result = NULL ;
|
||||
g_return_val_if_fail (a_this, NULL) ;
|
||||
|
||||
result = cr_string_new_from_gstring (a_this->stryng) ;
|
||||
if (!result) {
|
||||
cr_utils_trace_info ("Out of memory") ;
|
||||
return NULL ;
|
||||
}
|
||||
cr_parsing_location_copy (&result->location,
|
||||
&a_this->location) ;
|
||||
return result ;
|
||||
}
|
||||
|
||||
gchar *
|
||||
cr_string_dup2 (CRString const *a_this)
|
||||
{
|
||||
gchar *result = NULL ;
|
||||
|
||||
g_return_val_if_fail (a_this, NULL) ;
|
||||
|
||||
if (a_this
|
||||
&& a_this->stryng
|
||||
&& a_this->stryng->str) {
|
||||
result = g_strndup (a_this->stryng->str,
|
||||
a_this->stryng->len) ;
|
||||
}
|
||||
return result ;
|
||||
}
|
||||
|
||||
/**
|
||||
*Returns a pointer to the internal raw NULL terminated string
|
||||
*of the current instance of #CRString.
|
||||
*@param a_this the current instance of #CRString
|
||||
*/
|
||||
const gchar *
|
||||
cr_string_peek_raw_str (CRString const *a_this)
|
||||
{
|
||||
g_return_val_if_fail (a_this, NULL) ;
|
||||
|
||||
if (a_this->stryng && a_this->stryng->str)
|
||||
return a_this->stryng->str ;
|
||||
return NULL ;
|
||||
}
|
||||
|
||||
/**
|
||||
*Returns the length of the internal raw NULL terminated
|
||||
*string of the current instance of #CRString.
|
||||
*@param a_this the current instance of #CRString.
|
||||
*@return the len of the internal raw NULL termninated string,
|
||||
*of -1 if no length can be returned.
|
||||
*/
|
||||
gint
|
||||
cr_string_peek_raw_str_len (CRString const *a_this)
|
||||
{
|
||||
g_return_val_if_fail (a_this && a_this->stryng,
|
||||
-1) ;
|
||||
return a_this->stryng->len ;
|
||||
}
|
||||
|
||||
/**
|
||||
*@param a_this the #CRString to destroy.
|
||||
*/
|
||||
void
|
||||
cr_string_destroy (CRString *a_this)
|
||||
{
|
||||
g_return_if_fail (a_this) ;
|
||||
|
||||
if (a_this->stryng) {
|
||||
g_string_free (a_this->stryng, TRUE) ;
|
||||
a_this->stryng = NULL ;
|
||||
}
|
||||
g_free (a_this) ;
|
||||
}
|
76
src/st/croco/cr-string.h
Normal file
76
src/st/croco/cr-string.h
Normal file
@ -0,0 +1,76 @@
|
||||
/* -*- Mode: C; indent-tabs-mode:nil; c-basic-offset: 8-*- */
|
||||
|
||||
/*
|
||||
* This file is part of The Croco Library
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of version 2.1 of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*
|
||||
* See COPYRIGHTS file for copyright information.
|
||||
*/
|
||||
|
||||
/**
|
||||
*@file
|
||||
*Declaration file of the #CRString class.
|
||||
*/
|
||||
|
||||
#ifndef __CR_STRING_H__
|
||||
#define __CR_STRING_H__
|
||||
|
||||
#include <glib.h>
|
||||
#include "cr-utils.h"
|
||||
#include "cr-parsing-location.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _CRString CRString ;
|
||||
|
||||
/**
|
||||
*This is a ship implementation of string based on GString.
|
||||
*Actually, the aim of CRString is to store the parsing location
|
||||
*(line,column,byte offset) at which a given string has been parsed
|
||||
*in the input CSS.
|
||||
*So this class has a gstring field of type GString that users can
|
||||
*freely manipulate, and also a CRParginLocation type where the
|
||||
*parsing location is store. If you don't want to deal with parsing
|
||||
*location stuffs, then use GString instead. If we were in C++ for example,
|
||||
*CRString would just inherit GString and just add accessors to
|
||||
*the CRParsingLocation data ... but we are not and we still have
|
||||
*to provide the parsing location information.
|
||||
*/
|
||||
struct _CRString {
|
||||
/**
|
||||
*The GString where all the string
|
||||
*operation happen.
|
||||
*/
|
||||
GString *stryng ;
|
||||
/**
|
||||
*The parsing location storage area.
|
||||
*/
|
||||
CRParsingLocation location ;
|
||||
} ;
|
||||
|
||||
CRString * cr_string_new (void) ;
|
||||
|
||||
CRString *cr_string_new_from_string (const gchar * a_string) ;
|
||||
CRString * cr_string_new_from_gstring (GString const *a_string) ;
|
||||
CRString *cr_string_dup (CRString const *a_this) ;
|
||||
gchar *cr_string_dup2 (CRString const *a_this) ;
|
||||
const gchar *cr_string_peek_raw_str (CRString const *a_this) ;
|
||||
gint cr_string_peek_raw_str_len (CRString const *a_this) ;
|
||||
void cr_string_destroy (CRString *a_this) ;
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif
|
178
src/st/croco/cr-stylesheet.c
Normal file
178
src/st/croco/cr-stylesheet.c
Normal file
@ -0,0 +1,178 @@
|
||||
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
|
||||
|
||||
/*
|
||||
* This file is part of The Croco Library
|
||||
*
|
||||
* Copyright (C) 2002-2004 Dodji Seketeli
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of version 2.1 of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*/
|
||||
|
||||
#include "string.h"
|
||||
#include "cr-stylesheet.h"
|
||||
|
||||
/**
|
||||
*@file
|
||||
*The definition of the #CRStyleSheet class
|
||||
*/
|
||||
|
||||
/**
|
||||
*Constructor of the #CRStyleSheet class.
|
||||
*@param the initial list of css statements.
|
||||
*@return the newly built css2 stylesheet, or NULL in case of error.
|
||||
*/
|
||||
CRStyleSheet *
|
||||
cr_stylesheet_new (CRStatement * a_stmts)
|
||||
{
|
||||
CRStyleSheet *result;
|
||||
|
||||
result = g_try_malloc (sizeof (CRStyleSheet));
|
||||
if (!result) {
|
||||
cr_utils_trace_info ("Out of memory");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset (result, 0, sizeof (CRStyleSheet));
|
||||
|
||||
if (a_stmts)
|
||||
result->statements = a_stmts;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*@param a_this the current instance of #CRStyleSheet
|
||||
*@return the serialized stylesheet.
|
||||
*/
|
||||
gchar *
|
||||
cr_stylesheet_to_string (CRStyleSheet const *a_this)
|
||||
{
|
||||
gchar *str = NULL;
|
||||
GString *stringue = NULL;
|
||||
CRStatement const *cur_stmt = NULL;
|
||||
|
||||
g_return_val_if_fail (a_this, NULL);
|
||||
|
||||
if (a_this->statements) {
|
||||
stringue = g_string_new (NULL) ;
|
||||
g_return_val_if_fail (stringue, NULL) ;
|
||||
}
|
||||
for (cur_stmt = a_this->statements;
|
||||
cur_stmt; cur_stmt = cur_stmt->next) {
|
||||
if (cur_stmt->prev) {
|
||||
g_string_append (stringue, "\n\n") ;
|
||||
}
|
||||
str = cr_statement_to_string (cur_stmt, 0) ;
|
||||
if (str) {
|
||||
g_string_append (stringue, str) ;
|
||||
g_free (str) ;
|
||||
str = NULL ;
|
||||
}
|
||||
}
|
||||
if (stringue) {
|
||||
str = stringue->str ;
|
||||
g_string_free (stringue, FALSE) ;
|
||||
stringue = NULL ;
|
||||
}
|
||||
return str ;
|
||||
}
|
||||
|
||||
/**
|
||||
*Dumps the current css2 stylesheet to a file.
|
||||
*@param a_this the current instance of #CRStyleSheet.
|
||||
*@param a_fp the destination file
|
||||
*/
|
||||
void
|
||||
cr_stylesheet_dump (CRStyleSheet const * a_this, FILE * a_fp)
|
||||
{
|
||||
gchar *str = NULL ;
|
||||
|
||||
g_return_if_fail (a_this);
|
||||
|
||||
str = cr_stylesheet_to_string (a_this) ;
|
||||
if (str) {
|
||||
fprintf (a_fp, "%s", str) ;
|
||||
g_free (str) ;
|
||||
str = NULL ;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*Return the number of rules in the stylesheet.
|
||||
*@param a_this the current instance of #CRStyleSheet.
|
||||
*@return number of rules in the stylesheet.
|
||||
*/
|
||||
gint
|
||||
cr_stylesheet_nr_rules (CRStyleSheet const * a_this)
|
||||
{
|
||||
g_return_val_if_fail (a_this, -1);
|
||||
|
||||
return cr_statement_nr_rules (a_this->statements);
|
||||
}
|
||||
|
||||
/**
|
||||
*Use an index to get a CRStatement from the rules in a given stylesheet.
|
||||
*@param a_this the current instance of #CRStatement.
|
||||
*@param itemnr the index into the rules.
|
||||
*@return CRStatement at position itemnr, if itemnr > number of rules - 1,
|
||||
*it will return NULL.
|
||||
*/
|
||||
CRStatement *
|
||||
cr_stylesheet_statement_get_from_list (CRStyleSheet * a_this, int itemnr)
|
||||
{
|
||||
g_return_val_if_fail (a_this, NULL);
|
||||
|
||||
return cr_statement_get_from_list (a_this->statements, itemnr);
|
||||
}
|
||||
|
||||
void
|
||||
cr_stylesheet_ref (CRStyleSheet * a_this)
|
||||
{
|
||||
g_return_if_fail (a_this);
|
||||
|
||||
a_this->ref_count++;
|
||||
}
|
||||
|
||||
gboolean
|
||||
cr_stylesheet_unref (CRStyleSheet * a_this)
|
||||
{
|
||||
g_return_val_if_fail (a_this, FALSE);
|
||||
|
||||
if (a_this->ref_count)
|
||||
a_this->ref_count--;
|
||||
|
||||
if (!a_this->ref_count) {
|
||||
cr_stylesheet_destroy (a_this);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
*Destructor of the #CRStyleSheet class.
|
||||
*@param a_this the current instance of the #CRStyleSheet class.
|
||||
*/
|
||||
void
|
||||
cr_stylesheet_destroy (CRStyleSheet * a_this)
|
||||
{
|
||||
g_return_if_fail (a_this);
|
||||
|
||||
if (a_this->statements) {
|
||||
cr_statement_destroy (a_this->statements);
|
||||
a_this->statements = NULL;
|
||||
}
|
||||
g_free (a_this);
|
||||
}
|
102
src/st/croco/cr-stylesheet.h
Normal file
102
src/st/croco/cr-stylesheet.h
Normal file
@ -0,0 +1,102 @@
|
||||
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
|
||||
|
||||
/*
|
||||
* This file is part of The Croco Library
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of version 2.1 of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*
|
||||
* see COPYRIGHTS file for copyright information.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __CR_STYLESHEET_H__
|
||||
#define __CR_STYLESHEET_H__
|
||||
|
||||
#include "cr-utils.h"
|
||||
#include "cr-statement.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/**
|
||||
*@file
|
||||
*The declaration of the #CRStyleSheet class.
|
||||
*/
|
||||
|
||||
|
||||
enum CRStyleOrigin
|
||||
{
|
||||
/*Please don't change the order of
|
||||
*the values enumerated here ...
|
||||
*New values should be added at the end,
|
||||
*just before ORIGIN_END.
|
||||
*/
|
||||
ORIGIN_UA = 0,
|
||||
ORIGIN_USER,
|
||||
ORIGIN_AUTHOR,
|
||||
|
||||
/*must always be the last one*/
|
||||
NB_ORIGINS
|
||||
} ;
|
||||
|
||||
/**
|
||||
*An abstraction of a css stylesheet as defined
|
||||
*by the css2 spec in chapter 4.
|
||||
*/
|
||||
struct _CRStyleSheet
|
||||
{
|
||||
/**The css statements list*/
|
||||
CRStatement *statements ;
|
||||
|
||||
enum CRStyleOrigin origin ;
|
||||
|
||||
/*the parent import rule, if any.*/
|
||||
CRStatement *parent_import_rule ;
|
||||
|
||||
/**custom data used by libcroco*/
|
||||
gpointer croco_data ;
|
||||
|
||||
/**
|
||||
*custom application data pointer
|
||||
*Can be used by applications.
|
||||
*/
|
||||
gpointer app_data ;
|
||||
|
||||
/**
|
||||
*the reference count of this insance
|
||||
*Please, don't never ever modify it
|
||||
*directly. Use cr_stylesheet_ref()
|
||||
*and cr_stylesheet_unref() instead.
|
||||
*/
|
||||
gulong ref_count ;
|
||||
} ;
|
||||
|
||||
CRStyleSheet * cr_stylesheet_new (CRStatement *a_stmts) ;
|
||||
|
||||
gchar * cr_stylesheet_to_string (CRStyleSheet const *a_this) ;
|
||||
void cr_stylesheet_dump (CRStyleSheet const *a_this, FILE *a_fp) ;
|
||||
|
||||
gint cr_stylesheet_nr_rules (CRStyleSheet const *a_this) ;
|
||||
|
||||
CRStatement * cr_stylesheet_statement_get_from_list (CRStyleSheet *a_this, int itemnr) ;
|
||||
|
||||
void cr_stylesheet_ref (CRStyleSheet *a_this) ;
|
||||
|
||||
gboolean cr_stylesheet_unref (CRStyleSheet *a_this) ;
|
||||
|
||||
void cr_stylesheet_destroy (CRStyleSheet *a_this) ;
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /*__CR_STYLESHEET_H__*/
|
790
src/st/croco/cr-term.c
Normal file
790
src/st/croco/cr-term.c
Normal file
@ -0,0 +1,790 @@
|
||||
/* -*- Mode: C; indent-tabs-mode:nil; c-basic-offset: 8-*- */
|
||||
|
||||
/*
|
||||
* This file is part of The Croco Library
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of version 2.1 of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*
|
||||
* Author: Dodji Seketeli
|
||||
* See COPYRIGHTS file for copyright information.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "cr-term.h"
|
||||
#include "cr-num.h"
|
||||
#include "cr-parser.h"
|
||||
|
||||
/**
|
||||
*@file
|
||||
*Definition of the #CRTem class.
|
||||
*/
|
||||
|
||||
static void
|
||||
cr_term_clear (CRTerm * a_this)
|
||||
{
|
||||
g_return_if_fail (a_this);
|
||||
|
||||
switch (a_this->type) {
|
||||
case TERM_NUMBER:
|
||||
if (a_this->content.num) {
|
||||
cr_num_destroy (a_this->content.num);
|
||||
a_this->content.num = NULL;
|
||||
}
|
||||
break;
|
||||
|
||||
case TERM_FUNCTION:
|
||||
if (a_this->ext_content.func_param) {
|
||||
cr_term_destroy (a_this->ext_content.func_param);
|
||||
a_this->ext_content.func_param = NULL;
|
||||
}
|
||||
case TERM_STRING:
|
||||
case TERM_IDENT:
|
||||
case TERM_URI:
|
||||
case TERM_HASH:
|
||||
if (a_this->content.str) {
|
||||
cr_string_destroy (a_this->content.str);
|
||||
a_this->content.str = NULL;
|
||||
}
|
||||
break;
|
||||
|
||||
case TERM_RGB:
|
||||
if (a_this->content.rgb) {
|
||||
cr_rgb_destroy (a_this->content.rgb);
|
||||
a_this->content.rgb = NULL;
|
||||
}
|
||||
break;
|
||||
|
||||
case TERM_UNICODERANGE:
|
||||
case TERM_NO_TYPE:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
a_this->type = TERM_NO_TYPE;
|
||||
}
|
||||
|
||||
/**
|
||||
*Instanciate a #CRTerm.
|
||||
*@return the newly build instance
|
||||
*of #CRTerm.
|
||||
*/
|
||||
CRTerm *
|
||||
cr_term_new (void)
|
||||
{
|
||||
CRTerm *result = NULL;
|
||||
|
||||
result = g_try_malloc (sizeof (CRTerm));
|
||||
if (!result) {
|
||||
cr_utils_trace_info ("Out of memory");
|
||||
return NULL;
|
||||
}
|
||||
memset (result, 0, sizeof (CRTerm));
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*Parses an expresion as defined by the css2 spec
|
||||
*and builds the expression as a list of terms.
|
||||
*@param a_buf the buffer to parse.
|
||||
*@return a pointer to the first term of the expression or
|
||||
*NULL if parsing failed.
|
||||
*/
|
||||
CRTerm *
|
||||
cr_term_parse_expression_from_buf (const guchar * a_buf,
|
||||
enum CREncoding a_encoding)
|
||||
{
|
||||
CRParser *parser = NULL;
|
||||
CRTerm *result = NULL;
|
||||
enum CRStatus status = CR_OK;
|
||||
|
||||
g_return_val_if_fail (a_buf, NULL);
|
||||
|
||||
parser = cr_parser_new_from_buf ((guchar*)a_buf, strlen ((const char *) a_buf),
|
||||
a_encoding, FALSE);
|
||||
g_return_val_if_fail (parser, NULL);
|
||||
|
||||
status = cr_parser_try_to_skip_spaces_and_comments (parser);
|
||||
if (status != CR_OK) {
|
||||
goto cleanup;
|
||||
}
|
||||
status = cr_parser_parse_expr (parser, &result);
|
||||
if (status != CR_OK) {
|
||||
if (result) {
|
||||
cr_term_destroy (result);
|
||||
result = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
cleanup:
|
||||
if (parser) {
|
||||
cr_parser_destroy (parser);
|
||||
parser = NULL;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
enum CRStatus
|
||||
cr_term_set_number (CRTerm * a_this, CRNum * a_num)
|
||||
{
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
|
||||
|
||||
cr_term_clear (a_this);
|
||||
|
||||
a_this->type = TERM_NUMBER;
|
||||
a_this->content.num = a_num;
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
enum CRStatus
|
||||
cr_term_set_function (CRTerm * a_this, CRString * a_func_name,
|
||||
CRTerm * a_func_param)
|
||||
{
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
|
||||
|
||||
cr_term_clear (a_this);
|
||||
|
||||
a_this->type = TERM_FUNCTION;
|
||||
a_this->content.str = a_func_name;
|
||||
a_this->ext_content.func_param = a_func_param;
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
enum CRStatus
|
||||
cr_term_set_string (CRTerm * a_this, CRString * a_str)
|
||||
{
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
|
||||
|
||||
cr_term_clear (a_this);
|
||||
|
||||
a_this->type = TERM_STRING;
|
||||
a_this->content.str = a_str;
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
enum CRStatus
|
||||
cr_term_set_ident (CRTerm * a_this, CRString * a_str)
|
||||
{
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
|
||||
|
||||
cr_term_clear (a_this);
|
||||
|
||||
a_this->type = TERM_IDENT;
|
||||
a_this->content.str = a_str;
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
enum CRStatus
|
||||
cr_term_set_uri (CRTerm * a_this, CRString * a_str)
|
||||
{
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
|
||||
|
||||
cr_term_clear (a_this);
|
||||
|
||||
a_this->type = TERM_URI;
|
||||
a_this->content.str = a_str;
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
enum CRStatus
|
||||
cr_term_set_rgb (CRTerm * a_this, CRRgb * a_rgb)
|
||||
{
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
|
||||
|
||||
cr_term_clear (a_this);
|
||||
|
||||
a_this->type = TERM_RGB;
|
||||
a_this->content.rgb = a_rgb;
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
enum CRStatus
|
||||
cr_term_set_hash (CRTerm * a_this, CRString * a_str)
|
||||
{
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
|
||||
|
||||
cr_term_clear (a_this);
|
||||
|
||||
a_this->type = TERM_HASH;
|
||||
a_this->content.str = a_str;
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
*Appends a new term to the current list of #CRTerm.
|
||||
*
|
||||
*@param a_this the "this pointer" of the current instance
|
||||
*of #CRTerm .
|
||||
*@param a_new_term the term to append.
|
||||
*@return the list of terms with the a_new_term appended to it.
|
||||
*/
|
||||
CRTerm *
|
||||
cr_term_append_term (CRTerm * a_this, CRTerm * a_new_term)
|
||||
{
|
||||
CRTerm *cur = NULL;
|
||||
|
||||
g_return_val_if_fail (a_new_term, NULL);
|
||||
|
||||
if (a_this == NULL)
|
||||
return a_new_term;
|
||||
|
||||
for (cur = a_this; cur->next; cur = cur->next) ;
|
||||
|
||||
cur->next = a_new_term;
|
||||
a_new_term->prev = cur;
|
||||
|
||||
return a_this;
|
||||
}
|
||||
|
||||
/**
|
||||
*Prepends a term to the list of terms represented by a_this.
|
||||
*
|
||||
*@param a_this the "this pointer" of the current instance of
|
||||
*#CRTerm .
|
||||
*@param a_new_term the term to prepend.
|
||||
*@return the head of the new list.
|
||||
*/
|
||||
CRTerm *
|
||||
cr_term_prepend_term (CRTerm * a_this, CRTerm * a_new_term)
|
||||
{
|
||||
g_return_val_if_fail (a_this && a_new_term, NULL);
|
||||
|
||||
a_new_term->next = a_this;
|
||||
a_this->prev = a_new_term;
|
||||
|
||||
return a_new_term;
|
||||
}
|
||||
|
||||
/**
|
||||
*Serializes the expression represented by
|
||||
*the chained instances of #CRterm.
|
||||
*@param a_this the current instance of #CRTerm
|
||||
*@return the zero terminated string containing the serialized
|
||||
*form of #CRTerm. MUST BE FREED BY THE CALLER using g_free().
|
||||
*/
|
||||
guchar *
|
||||
cr_term_to_string (CRTerm const * a_this)
|
||||
{
|
||||
GString *str_buf = NULL;
|
||||
CRTerm const *cur = NULL;
|
||||
guchar *result = NULL,
|
||||
*content = NULL;
|
||||
|
||||
g_return_val_if_fail (a_this, NULL);
|
||||
|
||||
str_buf = g_string_new (NULL);
|
||||
g_return_val_if_fail (str_buf, NULL);
|
||||
|
||||
for (cur = a_this; cur; cur = cur->next) {
|
||||
if ((cur->content.str == NULL)
|
||||
&& (cur->content.num == NULL)
|
||||
&& (cur->content.str == NULL)
|
||||
&& (cur->content.rgb == NULL))
|
||||
continue;
|
||||
|
||||
switch (cur->the_operator) {
|
||||
case DIVIDE:
|
||||
g_string_append (str_buf, " / ");
|
||||
break;
|
||||
|
||||
case COMMA:
|
||||
g_string_append (str_buf, ", ");
|
||||
break;
|
||||
|
||||
case NO_OP:
|
||||
if (cur->prev) {
|
||||
g_string_append (str_buf, " ");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
switch (cur->unary_op) {
|
||||
case PLUS_UOP:
|
||||
g_string_append (str_buf, "+");
|
||||
break;
|
||||
|
||||
case MINUS_UOP:
|
||||
g_string_append (str_buf, "-");
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (cur->type) {
|
||||
case TERM_NUMBER:
|
||||
if (cur->content.num) {
|
||||
content = cr_num_to_string (cur->content.num);
|
||||
}
|
||||
|
||||
if (content) {
|
||||
g_string_append (str_buf, (const gchar *) content);
|
||||
g_free (content);
|
||||
content = NULL;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case TERM_FUNCTION:
|
||||
if (cur->content.str) {
|
||||
content = (guchar *) g_strndup
|
||||
(cur->content.str->stryng->str,
|
||||
cur->content.str->stryng->len);
|
||||
}
|
||||
|
||||
if (content) {
|
||||
g_string_append_printf (str_buf, "%s(",
|
||||
content);
|
||||
|
||||
if (cur->ext_content.func_param) {
|
||||
guchar *tmp_str = NULL;
|
||||
|
||||
tmp_str = cr_term_to_string
|
||||
(cur->
|
||||
ext_content.func_param);
|
||||
|
||||
if (tmp_str) {
|
||||
g_string_append (str_buf,
|
||||
(const gchar *) tmp_str);
|
||||
g_free (tmp_str);
|
||||
tmp_str = NULL;
|
||||
}
|
||||
}
|
||||
g_string_append (str_buf, ")");
|
||||
g_free (content);
|
||||
content = NULL;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case TERM_STRING:
|
||||
if (cur->content.str) {
|
||||
content = (guchar *) g_strndup
|
||||
(cur->content.str->stryng->str,
|
||||
cur->content.str->stryng->len);
|
||||
}
|
||||
|
||||
if (content) {
|
||||
g_string_append_printf (str_buf,
|
||||
"\"%s\"", content);
|
||||
g_free (content);
|
||||
content = NULL;
|
||||
}
|
||||
break;
|
||||
|
||||
case TERM_IDENT:
|
||||
if (cur->content.str) {
|
||||
content = (guchar *) g_strndup
|
||||
(cur->content.str->stryng->str,
|
||||
cur->content.str->stryng->len);
|
||||
}
|
||||
|
||||
if (content) {
|
||||
g_string_append (str_buf, (const gchar *) content);
|
||||
g_free (content);
|
||||
content = NULL;
|
||||
}
|
||||
break;
|
||||
|
||||
case TERM_URI:
|
||||
if (cur->content.str) {
|
||||
content = (guchar *) g_strndup
|
||||
(cur->content.str->stryng->str,
|
||||
cur->content.str->stryng->len);
|
||||
}
|
||||
|
||||
if (content) {
|
||||
g_string_append_printf
|
||||
(str_buf, "url(%s)", content);
|
||||
g_free (content);
|
||||
content = NULL;
|
||||
}
|
||||
break;
|
||||
|
||||
case TERM_RGB:
|
||||
if (cur->content.rgb) {
|
||||
guchar *tmp_str = NULL;
|
||||
|
||||
g_string_append (str_buf, "rgb(");
|
||||
tmp_str = cr_rgb_to_string (cur->content.rgb);
|
||||
|
||||
if (tmp_str) {
|
||||
g_string_append (str_buf, (const gchar *) tmp_str);
|
||||
g_free (tmp_str);
|
||||
tmp_str = NULL;
|
||||
}
|
||||
g_string_append (str_buf, ")");
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case TERM_UNICODERANGE:
|
||||
g_string_append
|
||||
(str_buf,
|
||||
"?found unicoderange: dump not supported yet?");
|
||||
break;
|
||||
|
||||
case TERM_HASH:
|
||||
if (cur->content.str) {
|
||||
content = (guchar *) g_strndup
|
||||
(cur->content.str->stryng->str,
|
||||
cur->content.str->stryng->len);
|
||||
}
|
||||
|
||||
if (content) {
|
||||
g_string_append_printf (str_buf,
|
||||
"#%s", content);
|
||||
g_free (content);
|
||||
content = NULL;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
g_string_append (str_buf,
|
||||
"Unrecognized Term type");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (str_buf) {
|
||||
result =(guchar *) str_buf->str;
|
||||
g_string_free (str_buf, FALSE);
|
||||
str_buf = NULL;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
guchar *
|
||||
cr_term_one_to_string (CRTerm const * a_this)
|
||||
{
|
||||
GString *str_buf = NULL;
|
||||
guchar *result = NULL,
|
||||
*content = NULL;
|
||||
|
||||
g_return_val_if_fail (a_this, NULL);
|
||||
|
||||
str_buf = g_string_new (NULL);
|
||||
g_return_val_if_fail (str_buf, NULL);
|
||||
|
||||
if ((a_this->content.str == NULL)
|
||||
&& (a_this->content.num == NULL)
|
||||
&& (a_this->content.str == NULL)
|
||||
&& (a_this->content.rgb == NULL))
|
||||
return NULL ;
|
||||
|
||||
switch (a_this->the_operator) {
|
||||
case DIVIDE:
|
||||
g_string_append_printf (str_buf, " / ");
|
||||
break;
|
||||
|
||||
case COMMA:
|
||||
g_string_append_printf (str_buf, ", ");
|
||||
break;
|
||||
|
||||
case NO_OP:
|
||||
if (a_this->prev) {
|
||||
g_string_append_printf (str_buf, " ");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
switch (a_this->unary_op) {
|
||||
case PLUS_UOP:
|
||||
g_string_append_printf (str_buf, "+");
|
||||
break;
|
||||
|
||||
case MINUS_UOP:
|
||||
g_string_append_printf (str_buf, "-");
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (a_this->type) {
|
||||
case TERM_NUMBER:
|
||||
if (a_this->content.num) {
|
||||
content = cr_num_to_string (a_this->content.num);
|
||||
}
|
||||
|
||||
if (content) {
|
||||
g_string_append (str_buf, (const gchar *) content);
|
||||
g_free (content);
|
||||
content = NULL;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case TERM_FUNCTION:
|
||||
if (a_this->content.str) {
|
||||
content = (guchar *) g_strndup
|
||||
(a_this->content.str->stryng->str,
|
||||
a_this->content.str->stryng->len);
|
||||
}
|
||||
|
||||
if (content) {
|
||||
g_string_append_printf (str_buf, "%s(",
|
||||
content);
|
||||
|
||||
if (a_this->ext_content.func_param) {
|
||||
guchar *tmp_str = NULL;
|
||||
|
||||
tmp_str = cr_term_to_string
|
||||
(a_this->
|
||||
ext_content.func_param);
|
||||
|
||||
if (tmp_str) {
|
||||
g_string_append_printf
|
||||
(str_buf,
|
||||
"%s", tmp_str);
|
||||
g_free (tmp_str);
|
||||
tmp_str = NULL;
|
||||
}
|
||||
|
||||
g_string_append_printf (str_buf, ")");
|
||||
g_free (content);
|
||||
content = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case TERM_STRING:
|
||||
if (a_this->content.str) {
|
||||
content = (guchar *) g_strndup
|
||||
(a_this->content.str->stryng->str,
|
||||
a_this->content.str->stryng->len);
|
||||
}
|
||||
|
||||
if (content) {
|
||||
g_string_append_printf (str_buf,
|
||||
"\"%s\"", content);
|
||||
g_free (content);
|
||||
content = NULL;
|
||||
}
|
||||
break;
|
||||
|
||||
case TERM_IDENT:
|
||||
if (a_this->content.str) {
|
||||
content = (guchar *) g_strndup
|
||||
(a_this->content.str->stryng->str,
|
||||
a_this->content.str->stryng->len);
|
||||
}
|
||||
|
||||
if (content) {
|
||||
g_string_append (str_buf, (const gchar *) content);
|
||||
g_free (content);
|
||||
content = NULL;
|
||||
}
|
||||
break;
|
||||
|
||||
case TERM_URI:
|
||||
if (a_this->content.str) {
|
||||
content = (guchar *) g_strndup
|
||||
(a_this->content.str->stryng->str,
|
||||
a_this->content.str->stryng->len);
|
||||
}
|
||||
|
||||
if (content) {
|
||||
g_string_append_printf
|
||||
(str_buf, "url(%s)", content);
|
||||
g_free (content);
|
||||
content = NULL;
|
||||
}
|
||||
break;
|
||||
|
||||
case TERM_RGB:
|
||||
if (a_this->content.rgb) {
|
||||
guchar *tmp_str = NULL;
|
||||
|
||||
g_string_append_printf (str_buf, "rgb(");
|
||||
tmp_str = cr_rgb_to_string (a_this->content.rgb);
|
||||
|
||||
if (tmp_str) {
|
||||
g_string_append (str_buf, (const gchar *) tmp_str);
|
||||
g_free (tmp_str);
|
||||
tmp_str = NULL;
|
||||
}
|
||||
g_string_append_printf (str_buf, ")");
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case TERM_UNICODERANGE:
|
||||
g_string_append_printf
|
||||
(str_buf,
|
||||
"?found unicoderange: dump not supported yet?");
|
||||
break;
|
||||
|
||||
case TERM_HASH:
|
||||
if (a_this->content.str) {
|
||||
content = (guchar *) g_strndup
|
||||
(a_this->content.str->stryng->str,
|
||||
a_this->content.str->stryng->len);
|
||||
}
|
||||
|
||||
if (content) {
|
||||
g_string_append_printf (str_buf,
|
||||
"#%s", content);
|
||||
g_free (content);
|
||||
content = NULL;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
g_string_append_printf (str_buf,
|
||||
"%s",
|
||||
"Unrecognized Term type");
|
||||
break;
|
||||
}
|
||||
|
||||
if (str_buf) {
|
||||
result = (guchar *) str_buf->str;
|
||||
g_string_free (str_buf, FALSE);
|
||||
str_buf = NULL;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*Dumps the expression (a list of terms connected by operators)
|
||||
*to a file.
|
||||
*TODO: finish the dump. The dump of some type of terms have not yet been
|
||||
*implemented.
|
||||
*@param a_this the current instance of #CRTerm.
|
||||
*@param a_fp the destination file pointer.
|
||||
*/
|
||||
void
|
||||
cr_term_dump (CRTerm const * a_this, FILE * a_fp)
|
||||
{
|
||||
guchar *content = NULL;
|
||||
|
||||
g_return_if_fail (a_this);
|
||||
|
||||
content = cr_term_to_string (a_this);
|
||||
|
||||
if (content) {
|
||||
fprintf (a_fp, "%s", content);
|
||||
g_free (content);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*Return the number of terms in the expression.
|
||||
*@param a_this the current instance of #CRTerm.
|
||||
*@return number of terms in the expression.
|
||||
*/
|
||||
int
|
||||
cr_term_nr_values (CRTerm const *a_this)
|
||||
{
|
||||
CRTerm const *cur = NULL ;
|
||||
int nr = 0;
|
||||
|
||||
g_return_val_if_fail (a_this, -1) ;
|
||||
|
||||
for (cur = a_this ; cur ; cur = cur->next)
|
||||
nr ++;
|
||||
return nr;
|
||||
}
|
||||
|
||||
/**
|
||||
*Use an index to get a CRTerm from the expression.
|
||||
*@param a_this the current instance of #CRTerm.
|
||||
*@param itemnr the index into the expression.
|
||||
*@return CRTerm at position itemnr, if itemnr > number of terms - 1,
|
||||
*it will return NULL.
|
||||
*/
|
||||
CRTerm *
|
||||
cr_term_get_from_list (CRTerm *a_this, int itemnr)
|
||||
{
|
||||
CRTerm *cur = NULL ;
|
||||
int nr = 0;
|
||||
|
||||
g_return_val_if_fail (a_this, NULL) ;
|
||||
|
||||
for (cur = a_this ; cur ; cur = cur->next)
|
||||
if (nr++ == itemnr)
|
||||
return cur;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
*Increments the reference counter of the current instance
|
||||
*of #CRTerm.*
|
||||
*@param a_this the current instance of #CRTerm.
|
||||
*/
|
||||
void
|
||||
cr_term_ref (CRTerm * a_this)
|
||||
{
|
||||
g_return_if_fail (a_this);
|
||||
|
||||
a_this->ref_count++;
|
||||
}
|
||||
|
||||
/**
|
||||
*Decrements the ref count of the current instance of
|
||||
*#CRTerm. If the ref count reaches zero, the instance is
|
||||
*destroyed.
|
||||
*@param a_this the current instance of #CRTerm.
|
||||
*@return TRUE if the current instance has been destroyed, FALSE otherwise.
|
||||
*/
|
||||
gboolean
|
||||
cr_term_unref (CRTerm * a_this)
|
||||
{
|
||||
g_return_val_if_fail (a_this, FALSE);
|
||||
|
||||
if (a_this->ref_count) {
|
||||
a_this->ref_count--;
|
||||
}
|
||||
|
||||
if (a_this->ref_count == 0) {
|
||||
cr_term_destroy (a_this);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
*The destructor of the the #CRTerm class.
|
||||
*@param a_this the "this pointer" of the current instance
|
||||
*of #CRTerm.
|
||||
*/
|
||||
void
|
||||
cr_term_destroy (CRTerm * a_this)
|
||||
{
|
||||
g_return_if_fail (a_this);
|
||||
|
||||
cr_term_clear (a_this);
|
||||
|
||||
if (a_this->next) {
|
||||
cr_term_destroy (a_this->next);
|
||||
a_this->next = NULL;
|
||||
}
|
||||
|
||||
if (a_this) {
|
||||
g_free (a_this);
|
||||
}
|
||||
|
||||
}
|
190
src/st/croco/cr-term.h
Normal file
190
src/st/croco/cr-term.h
Normal file
@ -0,0 +1,190 @@
|
||||
/* -*- Mode: C; indent-tabs-mode:nil; c-basic-offset: 8-*- */
|
||||
|
||||
/*
|
||||
* This file is part of The Croco Library
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of version 2.1 of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*
|
||||
* Author: Dodji Seketeli
|
||||
* See COPYRIGHTS file for copyright information.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <glib.h>
|
||||
#include "cr-utils.h"
|
||||
#include "cr-rgb.h"
|
||||
#include "cr-num.h"
|
||||
#include "cr-string.h"
|
||||
|
||||
#ifndef __CR_TERM_H__
|
||||
#define __CR_TERM_H__
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/**
|
||||
*@file
|
||||
*Declaration of the #CRTem class.
|
||||
*/
|
||||
|
||||
enum CRTermType
|
||||
{
|
||||
TERM_NO_TYPE = 0,
|
||||
TERM_NUMBER,
|
||||
TERM_FUNCTION,
|
||||
TERM_STRING,
|
||||
TERM_IDENT,
|
||||
TERM_URI,
|
||||
TERM_RGB,
|
||||
TERM_UNICODERANGE,
|
||||
TERM_HASH
|
||||
} ;
|
||||
|
||||
|
||||
enum UnaryOperator
|
||||
{
|
||||
NO_UNARY_UOP = 0,
|
||||
PLUS_UOP,
|
||||
MINUS_UOP,
|
||||
EMPTY_UNARY_UOP
|
||||
} ;
|
||||
|
||||
enum Operator
|
||||
{
|
||||
NO_OP = 0,
|
||||
DIVIDE,
|
||||
COMMA
|
||||
} ;
|
||||
|
||||
struct _CRTerm ;
|
||||
typedef struct _CRTerm CRTerm ;
|
||||
|
||||
/**
|
||||
*An abstraction of a css2 term as
|
||||
*defined in the CSS2 spec in appendix D.1:
|
||||
*term ::=
|
||||
*[ NUMBER S* | PERCENTAGE S* | LENGTH S* | EMS S* | EXS S*
|
||||
*| ANGLE S* | TIME S* | FREQ S* | function ]
|
||||
* | STRING S* | IDENT S* | URI S* | RGB S*
|
||||
*| UNICODERANGE S* | hexcolor
|
||||
*/
|
||||
struct _CRTerm
|
||||
{
|
||||
/**
|
||||
*The type of the term.
|
||||
*/
|
||||
enum CRTermType type ;
|
||||
|
||||
/**
|
||||
*The unary operator associated to
|
||||
*the current term.
|
||||
*/
|
||||
enum UnaryOperator unary_op ;
|
||||
|
||||
/**
|
||||
*The operator associated to the current term.
|
||||
*/
|
||||
enum Operator the_operator ;
|
||||
|
||||
|
||||
/**
|
||||
*The content of the term.
|
||||
*Depending of the type of the term,
|
||||
*this holds either a number, a percentage ...
|
||||
*/
|
||||
union
|
||||
{
|
||||
CRNum *num ;
|
||||
CRString * str ;
|
||||
CRRgb * rgb ;
|
||||
} content ;
|
||||
|
||||
/**
|
||||
*If the term is of type UNICODERANGE,
|
||||
*this field holds the upper bound of the range.
|
||||
*if the term is of type FUNCTION, this holds
|
||||
*an instance of CRTerm that represents
|
||||
* the expression which is the argument of the function.
|
||||
*/
|
||||
union
|
||||
{
|
||||
CRTerm *func_param ;
|
||||
} ext_content ;
|
||||
|
||||
/**
|
||||
*A spare pointer, just in case.
|
||||
*Can be used by the application.
|
||||
*/
|
||||
gpointer app_data ;
|
||||
|
||||
glong ref_count ;
|
||||
|
||||
/**
|
||||
*A pointer to the next term,
|
||||
*just in case this term is part of
|
||||
*an expression.
|
||||
*/
|
||||
CRTerm *next ;
|
||||
|
||||
/**
|
||||
*A pointer to the previous
|
||||
*term.
|
||||
*/
|
||||
CRTerm *prev ;
|
||||
CRParsingLocation location ;
|
||||
} ;
|
||||
|
||||
CRTerm * cr_term_parse_expression_from_buf (const guchar *a_buf,
|
||||
enum CREncoding a_encoding) ;
|
||||
CRTerm * cr_term_new (void) ;
|
||||
|
||||
enum CRStatus cr_term_set_number (CRTerm *a_this, CRNum *a_num) ;
|
||||
|
||||
enum CRStatus cr_term_set_function (CRTerm *a_this,
|
||||
CRString *a_func_name,
|
||||
CRTerm *a_func_param) ;
|
||||
|
||||
enum CRStatus cr_term_set_string (CRTerm *a_this, CRString *a_str) ;
|
||||
|
||||
enum CRStatus cr_term_set_ident (CRTerm *a_this, CRString *a_str) ;
|
||||
|
||||
enum CRStatus cr_term_set_uri (CRTerm *a_this, CRString *a_str) ;
|
||||
|
||||
enum CRStatus cr_term_set_rgb (CRTerm *a_this, CRRgb *a_rgb) ;
|
||||
|
||||
enum CRStatus cr_term_set_hash (CRTerm *a_this, CRString *a_str) ;
|
||||
|
||||
CRTerm * cr_term_append_term (CRTerm *a_this, CRTerm *a_new_term) ;
|
||||
|
||||
CRTerm * cr_term_prepend_term (CRTerm *a_this, CRTerm *a_new_term) ;
|
||||
|
||||
guchar * cr_term_to_string (CRTerm const *a_this) ;
|
||||
|
||||
guchar * cr_term_one_to_string (CRTerm const * a_this) ;
|
||||
|
||||
void cr_term_dump (CRTerm const *a_this, FILE *a_fp) ;
|
||||
|
||||
int cr_term_nr_values (CRTerm const *a_this) ;
|
||||
|
||||
CRTerm * cr_term_get_from_list (CRTerm *a_this, int itemnr) ;
|
||||
|
||||
void cr_term_ref (CRTerm *a_this) ;
|
||||
|
||||
gboolean cr_term_unref (CRTerm *a_this) ;
|
||||
|
||||
void cr_term_destroy (CRTerm * a_term) ;
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /*__CR_TERM_H__*/
|
2762
src/st/croco/cr-tknzr.c
Normal file
2762
src/st/croco/cr-tknzr.c
Normal file
File diff suppressed because it is too large
Load Diff
115
src/st/croco/cr-tknzr.h
Normal file
115
src/st/croco/cr-tknzr.h
Normal file
@ -0,0 +1,115 @@
|
||||
/* -*- Mode: C; indent-tabs-mode:nil; c-basic-offset: 8-*- */
|
||||
|
||||
/*
|
||||
* This file is part of The Croco Library
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of version 2.1 of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*
|
||||
* Author: Dodji Seketeli
|
||||
* See COPYRIGHTS file for coypyright information.
|
||||
*/
|
||||
|
||||
/**
|
||||
*@file
|
||||
*The declaration of the #CRTknzr (tokenizer)
|
||||
*class.
|
||||
*/
|
||||
|
||||
#ifndef __CR_TKNZR_H__
|
||||
#define __CR_TKNZR_H__
|
||||
|
||||
#include "cr-utils.h"
|
||||
#include "cr-input.h"
|
||||
#include "cr-token.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
||||
typedef struct _CRTknzr CRTknzr ;
|
||||
typedef struct _CRTknzrPriv CRTknzrPriv ;
|
||||
|
||||
/**
|
||||
*The tokenizer is the class that knows
|
||||
*about all the css token. Its main job is
|
||||
*to return the next token found in the character
|
||||
*input stream.
|
||||
*/
|
||||
struct _CRTknzr
|
||||
{
|
||||
/*the private data of the tokenizer.*/
|
||||
CRTknzrPriv *priv ;
|
||||
} ;
|
||||
|
||||
CRTknzr * cr_tknzr_new (CRInput *a_input) ;
|
||||
|
||||
CRTknzr * cr_tknzr_new_from_uri (const guchar *a_file_uri,
|
||||
enum CREncoding a_enc) ;
|
||||
|
||||
CRTknzr * cr_tknzr_new_from_buf (guchar *a_buf, gulong a_len,
|
||||
enum CREncoding a_enc,
|
||||
gboolean a_free_at_destroy) ;
|
||||
|
||||
gboolean cr_tknzr_unref (CRTknzr *a_this) ;
|
||||
|
||||
void cr_tknzr_ref (CRTknzr *a_this) ;
|
||||
|
||||
enum CRStatus cr_tknzr_read_byte (CRTknzr *a_this, guchar *a_byte) ;
|
||||
|
||||
enum CRStatus cr_tknzr_read_char (CRTknzr *a_this, guint32 *a_char);
|
||||
|
||||
enum CRStatus cr_tknzr_peek_char (CRTknzr *a_this, guint32 *a_char) ;
|
||||
|
||||
enum CRStatus cr_tknzr_peek_byte (CRTknzr *a_this, gulong a_offset,
|
||||
guchar *a_byte) ;
|
||||
|
||||
guchar cr_tknzr_peek_byte2 (CRTknzr *a_this, gulong a_offset,
|
||||
gboolean *a_eof) ;
|
||||
|
||||
enum CRStatus cr_tknzr_set_cur_pos (CRTknzr *a_this, CRInputPos *a_pos) ;
|
||||
|
||||
glong cr_tknzr_get_nb_bytes_left (CRTknzr *a_this) ;
|
||||
|
||||
enum CRStatus cr_tknzr_get_cur_pos (CRTknzr *a_this, CRInputPos *a_pos) ;
|
||||
|
||||
enum CRStatus cr_tknzr_get_parsing_location (CRTknzr *a_this,
|
||||
CRParsingLocation *a_loc) ;
|
||||
|
||||
enum CRStatus cr_tknzr_seek_index (CRTknzr *a_this,
|
||||
enum CRSeekPos a_origin,
|
||||
gint a_pos) ;
|
||||
|
||||
enum CRStatus cr_tknzr_get_cur_byte_addr (CRTknzr *a_this, guchar **a_addr) ;
|
||||
|
||||
|
||||
enum CRStatus cr_tknzr_consume_chars (CRTknzr *a_this, guint32 a_char,
|
||||
glong *a_nb_char) ;
|
||||
|
||||
enum CRStatus cr_tknzr_get_next_token (CRTknzr *a_this, CRToken ** a_tk) ;
|
||||
|
||||
enum CRStatus cr_tknzr_unget_token (CRTknzr *a_this, CRToken *a_token) ;
|
||||
|
||||
|
||||
enum CRStatus cr_tknzr_parse_token (CRTknzr *a_this, enum CRTokenType a_type,
|
||||
enum CRTokenExtraType a_et, gpointer a_res,
|
||||
gpointer a_extra_res) ;
|
||||
enum CRStatus cr_tknzr_set_input (CRTknzr *a_this, CRInput *a_input) ;
|
||||
|
||||
enum CRStatus cr_tknzr_get_input (CRTknzr *a_this, CRInput **a_input) ;
|
||||
|
||||
void cr_tknzr_destroy (CRTknzr *a_this) ;
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /*__CR_TKZNR_H__*/
|
636
src/st/croco/cr-token.c
Normal file
636
src/st/croco/cr-token.c
Normal file
@ -0,0 +1,636 @@
|
||||
/* -*- Mode: C; indent-tabs-mode:nil; c-basic-offset: 8-*- */
|
||||
|
||||
/*
|
||||
* This file is part of The Croco Library
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of version 2.1 of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*
|
||||
* Author: Dodji Seketeli
|
||||
* see COPYRIGHTS file for copyright information.
|
||||
*/
|
||||
|
||||
/**
|
||||
*@file
|
||||
*The definition of the #CRToken class.
|
||||
*Abstracts a css2 token.
|
||||
*/
|
||||
#include <string.h>
|
||||
#include "cr-token.h"
|
||||
|
||||
/*
|
||||
*TODO: write a CRToken::to_string() method.
|
||||
*/
|
||||
|
||||
/**
|
||||
*Frees the attributes of the current instance
|
||||
*of #CRtoken.
|
||||
*@param a_this the current instance of #CRToken.
|
||||
*/
|
||||
static void
|
||||
cr_token_clear (CRToken * a_this)
|
||||
{
|
||||
g_return_if_fail (a_this);
|
||||
|
||||
switch (a_this->type) {
|
||||
case S_TK:
|
||||
case CDO_TK:
|
||||
case CDC_TK:
|
||||
case INCLUDES_TK:
|
||||
case DASHMATCH_TK:
|
||||
case PAGE_SYM_TK:
|
||||
case MEDIA_SYM_TK:
|
||||
case FONT_FACE_SYM_TK:
|
||||
case CHARSET_SYM_TK:
|
||||
case IMPORT_SYM_TK:
|
||||
case IMPORTANT_SYM_TK:
|
||||
case SEMICOLON_TK:
|
||||
case NO_TK:
|
||||
case DELIM_TK:
|
||||
case CBO_TK:
|
||||
case CBC_TK:
|
||||
case BO_TK:
|
||||
case BC_TK:
|
||||
break;
|
||||
|
||||
case STRING_TK:
|
||||
case IDENT_TK:
|
||||
case HASH_TK:
|
||||
case URI_TK:
|
||||
case FUNCTION_TK:
|
||||
case COMMENT_TK:
|
||||
case ATKEYWORD_TK:
|
||||
if (a_this->u.str) {
|
||||
cr_string_destroy (a_this->u.str);
|
||||
a_this->u.str = NULL;
|
||||
}
|
||||
break;
|
||||
|
||||
case EMS_TK:
|
||||
case EXS_TK:
|
||||
case LENGTH_TK:
|
||||
case ANGLE_TK:
|
||||
case TIME_TK:
|
||||
case FREQ_TK:
|
||||
case PERCENTAGE_TK:
|
||||
case NUMBER_TK:
|
||||
case PO_TK:
|
||||
case PC_TK:
|
||||
if (a_this->u.num) {
|
||||
cr_num_destroy (a_this->u.num);
|
||||
a_this->u.num = NULL;
|
||||
}
|
||||
break;
|
||||
|
||||
case DIMEN_TK:
|
||||
if (a_this->u.num) {
|
||||
cr_num_destroy (a_this->u.num);
|
||||
a_this->u.num = NULL;
|
||||
}
|
||||
|
||||
if (a_this->dimen) {
|
||||
cr_string_destroy (a_this->dimen);
|
||||
a_this->dimen = NULL;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case RGB_TK:
|
||||
if (a_this->u.rgb) {
|
||||
cr_rgb_destroy (a_this->u.rgb) ;
|
||||
a_this->u.rgb = NULL ;
|
||||
}
|
||||
break ;
|
||||
|
||||
case UNICODERANGE_TK:
|
||||
/*not supported yet. */
|
||||
break;
|
||||
|
||||
default:
|
||||
cr_utils_trace_info ("I don't know how to clear this token\n") ;
|
||||
break;
|
||||
}
|
||||
|
||||
a_this->type = NO_TK;
|
||||
}
|
||||
|
||||
/**
|
||||
*Default constructor of
|
||||
*the #CRToken class.
|
||||
*@return the newly built instance of #CRToken.
|
||||
*/
|
||||
CRToken *
|
||||
cr_token_new (void)
|
||||
{
|
||||
CRToken *result = NULL;
|
||||
|
||||
result = g_try_malloc (sizeof (CRToken));
|
||||
|
||||
if (result == NULL) {
|
||||
cr_utils_trace_info ("Out of memory");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset (result, 0, sizeof (CRToken));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*Sets the type of curren instance of
|
||||
*#CRToken to 'S_TK' (S in the css2 spec)
|
||||
*@param a_this the current instance of #CRToken.
|
||||
*@return CR_OK upon successfull completion, an error
|
||||
*code otherwise.
|
||||
*/
|
||||
enum CRStatus
|
||||
cr_token_set_s (CRToken * a_this)
|
||||
{
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
|
||||
|
||||
cr_token_clear (a_this);
|
||||
|
||||
a_this->type = S_TK;
|
||||
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
*Sets the type of the current instance of
|
||||
*#CRToken to 'CDO_TK' (CDO as said by the css2 spec)
|
||||
*@param a_this the current instance of #CRToken.
|
||||
*@return CR_OK upon successfull completion, an error
|
||||
*code otherwise.
|
||||
*/
|
||||
enum CRStatus
|
||||
cr_token_set_cdo (CRToken * a_this)
|
||||
{
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
|
||||
|
||||
cr_token_clear (a_this);
|
||||
|
||||
a_this->type = CDO_TK;
|
||||
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
*Sets the type of the current token to
|
||||
*CDC_TK (CDC as said by the css2 spec).
|
||||
*@param a_this the current instance of #CRToken.
|
||||
*@return CR_OK upon successfull completion, an error
|
||||
*code otherwise.
|
||||
*/
|
||||
enum CRStatus
|
||||
cr_token_set_cdc (CRToken * a_this)
|
||||
{
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
|
||||
|
||||
cr_token_clear (a_this);
|
||||
|
||||
a_this->type = CDC_TK;
|
||||
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
*Sets the type of the current instance of
|
||||
*#CRToken to INCLUDES_TK (INCLUDES as said by the css2 spec).
|
||||
*@param a_this the current instance of #CRToken.
|
||||
*@return CR_OK upon successfull completion, an error
|
||||
*code otherwise.
|
||||
*/
|
||||
enum CRStatus
|
||||
cr_token_set_includes (CRToken * a_this)
|
||||
{
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
|
||||
|
||||
cr_token_clear (a_this);
|
||||
|
||||
a_this->type = INCLUDES_TK;
|
||||
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
*Sets the type of the current instance of
|
||||
*#CRToken to DASHMATCH_TK (DASHMATCH as said by the css2 spec).
|
||||
*@param a_this the current instance of #CRToken.
|
||||
*@return CR_OK upon successfull completion, an error
|
||||
*code otherwise.
|
||||
*/
|
||||
enum CRStatus
|
||||
cr_token_set_dashmatch (CRToken * a_this)
|
||||
{
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
|
||||
|
||||
cr_token_clear (a_this);
|
||||
|
||||
a_this->type = DASHMATCH_TK;
|
||||
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
enum CRStatus
|
||||
cr_token_set_comment (CRToken * a_this, CRString * a_str)
|
||||
{
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
|
||||
|
||||
cr_token_clear (a_this);
|
||||
a_this->type = COMMENT_TK;
|
||||
a_this->u.str = a_str ;
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
enum CRStatus
|
||||
cr_token_set_string (CRToken * a_this, CRString * a_str)
|
||||
{
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
|
||||
|
||||
cr_token_clear (a_this);
|
||||
|
||||
a_this->type = STRING_TK;
|
||||
|
||||
a_this->u.str = a_str ;
|
||||
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
enum CRStatus
|
||||
cr_token_set_ident (CRToken * a_this, CRString * a_ident)
|
||||
{
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
|
||||
|
||||
cr_token_clear (a_this);
|
||||
a_this->type = IDENT_TK;
|
||||
a_this->u.str = a_ident;
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
|
||||
enum CRStatus
|
||||
cr_token_set_function (CRToken * a_this, CRString * a_fun_name)
|
||||
{
|
||||
g_return_val_if_fail (a_this,
|
||||
CR_BAD_PARAM_ERROR);
|
||||
|
||||
cr_token_clear (a_this);
|
||||
a_this->type = FUNCTION_TK;
|
||||
a_this->u.str = a_fun_name;
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
enum CRStatus
|
||||
cr_token_set_hash (CRToken * a_this, CRString * a_hash)
|
||||
{
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
|
||||
|
||||
cr_token_clear (a_this);
|
||||
a_this->type = HASH_TK;
|
||||
a_this->u.str = a_hash;
|
||||
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
enum CRStatus
|
||||
cr_token_set_rgb (CRToken * a_this, CRRgb * a_rgb)
|
||||
{
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
|
||||
|
||||
cr_token_clear (a_this);
|
||||
a_this->type = RGB_TK;
|
||||
a_this->u.rgb = a_rgb;
|
||||
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
enum CRStatus
|
||||
cr_token_set_import_sym (CRToken * a_this)
|
||||
{
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
|
||||
|
||||
cr_token_clear (a_this);
|
||||
|
||||
a_this->type = IMPORT_SYM_TK;
|
||||
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
enum CRStatus
|
||||
cr_token_set_page_sym (CRToken * a_this)
|
||||
{
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
|
||||
|
||||
cr_token_clear (a_this);
|
||||
|
||||
a_this->type = PAGE_SYM_TK;
|
||||
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
enum CRStatus
|
||||
cr_token_set_media_sym (CRToken * a_this)
|
||||
{
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
|
||||
|
||||
cr_token_clear (a_this);
|
||||
|
||||
a_this->type = MEDIA_SYM_TK;
|
||||
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
enum CRStatus
|
||||
cr_token_set_font_face_sym (CRToken * a_this)
|
||||
{
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
|
||||
|
||||
cr_token_clear (a_this);
|
||||
a_this->type = FONT_FACE_SYM_TK;
|
||||
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
enum CRStatus
|
||||
cr_token_set_charset_sym (CRToken * a_this)
|
||||
{
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
|
||||
|
||||
cr_token_clear (a_this);
|
||||
a_this->type = CHARSET_SYM_TK;
|
||||
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
enum CRStatus
|
||||
cr_token_set_atkeyword (CRToken * a_this, CRString * a_atname)
|
||||
{
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
|
||||
|
||||
cr_token_clear (a_this);
|
||||
a_this->type = ATKEYWORD_TK;
|
||||
a_this->u.str = a_atname;
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
enum CRStatus
|
||||
cr_token_set_important_sym (CRToken * a_this)
|
||||
{
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
|
||||
cr_token_clear (a_this);
|
||||
a_this->type = IMPORTANT_SYM_TK;
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
enum CRStatus
|
||||
cr_token_set_ems (CRToken * a_this, CRNum * a_num)
|
||||
{
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
|
||||
cr_token_clear (a_this);
|
||||
a_this->type = EMS_TK;
|
||||
a_this->u.num = a_num;
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
enum CRStatus
|
||||
cr_token_set_exs (CRToken * a_this, CRNum * a_num)
|
||||
{
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
|
||||
cr_token_clear (a_this);
|
||||
a_this->type = EXS_TK;
|
||||
a_this->u.num = a_num;
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
enum CRStatus
|
||||
cr_token_set_length (CRToken * a_this, CRNum * a_num,
|
||||
enum CRTokenExtraType a_et)
|
||||
{
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
|
||||
|
||||
cr_token_clear (a_this);
|
||||
|
||||
a_this->type = LENGTH_TK;
|
||||
a_this->extra_type = a_et;
|
||||
a_this->u.num = a_num;
|
||||
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
enum CRStatus
|
||||
cr_token_set_angle (CRToken * a_this, CRNum * a_num,
|
||||
enum CRTokenExtraType a_et)
|
||||
{
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
|
||||
|
||||
cr_token_clear (a_this);
|
||||
|
||||
a_this->type = ANGLE_TK;
|
||||
a_this->extra_type = a_et;
|
||||
a_this->u.num = a_num;
|
||||
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
enum CRStatus
|
||||
cr_token_set_time (CRToken * a_this, CRNum * a_num,
|
||||
enum CRTokenExtraType a_et)
|
||||
{
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
|
||||
|
||||
cr_token_clear (a_this);
|
||||
|
||||
a_this->type = TIME_TK;
|
||||
a_this->extra_type = a_et;
|
||||
a_this->u.num = a_num;
|
||||
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
enum CRStatus
|
||||
cr_token_set_freq (CRToken * a_this, CRNum * a_num,
|
||||
enum CRTokenExtraType a_et)
|
||||
{
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
|
||||
|
||||
cr_token_clear (a_this);
|
||||
|
||||
a_this->type = FREQ_TK;
|
||||
a_this->extra_type = a_et;
|
||||
a_this->u.num = a_num;
|
||||
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
enum CRStatus
|
||||
cr_token_set_dimen (CRToken * a_this, CRNum * a_num,
|
||||
CRString * a_dim)
|
||||
{
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
|
||||
cr_token_clear (a_this);
|
||||
a_this->type = DIMEN_TK;
|
||||
a_this->u.num = a_num;
|
||||
a_this->dimen = a_dim;
|
||||
return CR_OK;
|
||||
|
||||
}
|
||||
|
||||
enum CRStatus
|
||||
cr_token_set_percentage (CRToken * a_this, CRNum * a_num)
|
||||
{
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
|
||||
|
||||
cr_token_clear (a_this);
|
||||
|
||||
a_this->type = PERCENTAGE_TK;
|
||||
a_this->u.num = a_num;
|
||||
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
enum CRStatus
|
||||
cr_token_set_number (CRToken * a_this, CRNum * a_num)
|
||||
{
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
|
||||
|
||||
cr_token_clear (a_this);
|
||||
|
||||
a_this->type = NUMBER_TK;
|
||||
a_this->u.num = a_num;
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
enum CRStatus
|
||||
cr_token_set_uri (CRToken * a_this, CRString * a_uri)
|
||||
{
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
|
||||
|
||||
cr_token_clear (a_this);
|
||||
|
||||
a_this->type = URI_TK;
|
||||
a_this->u.str = a_uri;
|
||||
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
enum CRStatus
|
||||
cr_token_set_delim (CRToken * a_this, guint32 a_char)
|
||||
{
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
|
||||
|
||||
cr_token_clear (a_this);
|
||||
|
||||
a_this->type = DELIM_TK;
|
||||
a_this->u.unichar = a_char;
|
||||
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
enum CRStatus
|
||||
cr_token_set_semicolon (CRToken * a_this)
|
||||
{
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
|
||||
|
||||
cr_token_clear (a_this);
|
||||
|
||||
a_this->type = SEMICOLON_TK;
|
||||
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
enum CRStatus
|
||||
cr_token_set_cbo (CRToken * a_this)
|
||||
{
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
|
||||
|
||||
cr_token_clear (a_this);
|
||||
|
||||
a_this->type = CBO_TK;
|
||||
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
enum CRStatus
|
||||
cr_token_set_cbc (CRToken * a_this)
|
||||
{
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
|
||||
|
||||
cr_token_clear (a_this);
|
||||
|
||||
a_this->type = CBC_TK;
|
||||
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
enum CRStatus
|
||||
cr_token_set_po (CRToken * a_this)
|
||||
{
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
|
||||
|
||||
cr_token_clear (a_this);
|
||||
|
||||
a_this->type = PO_TK;
|
||||
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
enum CRStatus
|
||||
cr_token_set_pc (CRToken * a_this)
|
||||
{
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
|
||||
|
||||
cr_token_clear (a_this);
|
||||
|
||||
a_this->type = PC_TK;
|
||||
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
enum CRStatus
|
||||
cr_token_set_bo (CRToken * a_this)
|
||||
{
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
|
||||
|
||||
cr_token_clear (a_this);
|
||||
|
||||
a_this->type = BO_TK;
|
||||
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
enum CRStatus
|
||||
cr_token_set_bc (CRToken * a_this)
|
||||
{
|
||||
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
|
||||
|
||||
cr_token_clear (a_this);
|
||||
|
||||
a_this->type = BC_TK;
|
||||
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
*The destructor of the #CRToken class.
|
||||
*@param a_this the current instance of #CRToken.
|
||||
*/
|
||||
void
|
||||
cr_token_destroy (CRToken * a_this)
|
||||
{
|
||||
g_return_if_fail (a_this);
|
||||
|
||||
cr_token_clear (a_this);
|
||||
|
||||
g_free (a_this);
|
||||
}
|
212
src/st/croco/cr-token.h
Normal file
212
src/st/croco/cr-token.h
Normal file
@ -0,0 +1,212 @@
|
||||
/* -*- Mode: C; indent-tabs-mode:nil; c-basic-offset: 8-*- */
|
||||
|
||||
/*
|
||||
* This file is part of The Croco Library
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of version 2.1 of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*
|
||||
* Author: Dodji Seketeli
|
||||
* See COPYRIGHTS file for copyright information.
|
||||
*/
|
||||
|
||||
#ifndef __CR_TOKEN_H__
|
||||
#define __CR_TOKEN_H__
|
||||
|
||||
#include "cr-utils.h"
|
||||
#include "cr-input.h"
|
||||
#include "cr-num.h"
|
||||
#include "cr-rgb.h"
|
||||
#include "cr-string.h"
|
||||
#include "cr-parsing-location.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
enum CRTokenType
|
||||
{
|
||||
NO_TK,
|
||||
S_TK,
|
||||
CDO_TK,
|
||||
CDC_TK,
|
||||
INCLUDES_TK,
|
||||
DASHMATCH_TK,
|
||||
COMMENT_TK,
|
||||
STRING_TK,
|
||||
IDENT_TK,
|
||||
HASH_TK,
|
||||
IMPORT_SYM_TK,
|
||||
PAGE_SYM_TK,
|
||||
MEDIA_SYM_TK,
|
||||
FONT_FACE_SYM_TK,
|
||||
CHARSET_SYM_TK,
|
||||
ATKEYWORD_TK,
|
||||
IMPORTANT_SYM_TK,
|
||||
EMS_TK,
|
||||
EXS_TK,
|
||||
LENGTH_TK,
|
||||
ANGLE_TK,
|
||||
TIME_TK,
|
||||
FREQ_TK,
|
||||
DIMEN_TK,
|
||||
PERCENTAGE_TK,
|
||||
NUMBER_TK,
|
||||
RGB_TK,
|
||||
URI_TK,
|
||||
FUNCTION_TK,
|
||||
UNICODERANGE_TK,
|
||||
SEMICOLON_TK,
|
||||
CBO_TK, /*opening curly bracket*/
|
||||
CBC_TK, /*closing curly bracket*/
|
||||
PO_TK, /*opening parenthesis*/
|
||||
PC_TK, /*closing parenthesis*/
|
||||
BO_TK, /*opening bracket*/
|
||||
BC_TK, /*closing bracket*/
|
||||
DELIM_TK
|
||||
} ;
|
||||
|
||||
enum CRTokenExtraType
|
||||
{
|
||||
NO_ET = 0,
|
||||
LENGTH_PX_ET,
|
||||
LENGTH_CM_ET,
|
||||
LENGTH_MM_ET,
|
||||
LENGTH_IN_ET,
|
||||
LENGTH_PT_ET,
|
||||
LENGTH_PC_ET,
|
||||
ANGLE_DEG_ET,
|
||||
ANGLE_RAD_ET,
|
||||
ANGLE_GRAD_ET,
|
||||
TIME_MS_ET,
|
||||
TIME_S_ET,
|
||||
FREQ_HZ_ET,
|
||||
FREQ_KHZ_ET
|
||||
} ;
|
||||
|
||||
typedef struct _CRToken CRToken ;
|
||||
|
||||
/**
|
||||
*This class abstracts a css2 token.
|
||||
*/
|
||||
struct _CRToken
|
||||
{
|
||||
enum CRTokenType type ;
|
||||
enum CRTokenExtraType extra_type ;
|
||||
CRInputPos pos ;
|
||||
|
||||
union
|
||||
{
|
||||
CRString *str ;
|
||||
CRRgb *rgb ;
|
||||
CRNum *num ;
|
||||
guint32 unichar ;
|
||||
} u ;
|
||||
|
||||
CRString * dimen ;
|
||||
CRParsingLocation location ;
|
||||
} ;
|
||||
|
||||
CRToken* cr_token_new (void) ;
|
||||
|
||||
enum CRStatus cr_token_set_s (CRToken *a_this) ;
|
||||
|
||||
enum CRStatus cr_token_set_cdo (CRToken *a_this) ;
|
||||
|
||||
enum CRStatus cr_token_set_cdc (CRToken *a_this) ;
|
||||
|
||||
enum CRStatus cr_token_set_includes (CRToken *a_this) ;
|
||||
|
||||
enum CRStatus cr_token_set_dashmatch (CRToken *a_this) ;
|
||||
|
||||
enum CRStatus cr_token_set_comment (CRToken *a_this, CRString *a_str) ;
|
||||
|
||||
enum CRStatus cr_token_set_string (CRToken *a_this, CRString *a_str) ;
|
||||
|
||||
enum CRStatus cr_token_set_ident (CRToken *a_this, CRString * a_ident) ;
|
||||
|
||||
enum CRStatus cr_token_set_hash (CRToken *a_this, CRString *a_hash) ;
|
||||
|
||||
enum CRStatus cr_token_set_rgb (CRToken *a_this, CRRgb *a_rgb) ;
|
||||
|
||||
enum CRStatus cr_token_set_import_sym (CRToken *a_this) ;
|
||||
|
||||
enum CRStatus cr_token_set_page_sym (CRToken *a_this) ;
|
||||
|
||||
enum CRStatus cr_token_set_media_sym (CRToken *a_this) ;
|
||||
|
||||
enum CRStatus cr_token_set_font_face_sym (CRToken *a_this) ;
|
||||
|
||||
enum CRStatus cr_token_set_charset_sym (CRToken *a_this) ;
|
||||
|
||||
enum CRStatus cr_token_set_atkeyword (CRToken *a_this, CRString *a_atname) ;
|
||||
|
||||
enum CRStatus cr_token_set_important_sym (CRToken *a_this) ;
|
||||
|
||||
enum CRStatus cr_token_set_ems (CRToken *a_this, CRNum *a_num) ;
|
||||
|
||||
enum CRStatus cr_token_set_exs (CRToken *a_this, CRNum *a_num) ;
|
||||
|
||||
enum CRStatus cr_token_set_length (CRToken *a_this, CRNum *a_num,
|
||||
enum CRTokenExtraType a_et) ;
|
||||
|
||||
enum CRStatus cr_token_set_angle (CRToken *a_this, CRNum *a_num,
|
||||
enum CRTokenExtraType a_et) ;
|
||||
|
||||
enum CRStatus cr_token_set_time (CRToken *a_this, CRNum *a_num,
|
||||
enum CRTokenExtraType a_et) ;
|
||||
|
||||
enum CRStatus cr_token_set_freq (CRToken *a_this, CRNum *a_num,
|
||||
enum CRTokenExtraType a_et) ;
|
||||
|
||||
enum CRStatus cr_token_set_dimen (CRToken *a_this, CRNum *a_num,
|
||||
CRString *a_dim) ;
|
||||
|
||||
enum CRStatus cr_token_set_percentage (CRToken *a_this, CRNum *a_num) ;
|
||||
|
||||
enum CRStatus cr_token_set_number (CRToken *a_this, CRNum *a_num) ;
|
||||
|
||||
enum CRStatus cr_token_set_uri (CRToken *a_this, CRString *a_uri) ;
|
||||
|
||||
enum CRStatus cr_token_set_function (CRToken *a_this,
|
||||
CRString *a_fun_name) ;
|
||||
|
||||
enum CRStatus cr_token_set_bc (CRToken *a_this) ;
|
||||
|
||||
enum CRStatus cr_token_set_bo (CRToken *a_this) ;
|
||||
|
||||
enum CRStatus cr_token_set_po (CRToken *a_this) ;
|
||||
|
||||
enum CRStatus cr_token_set_pc (CRToken *a_this) ;
|
||||
|
||||
enum CRStatus cr_token_set_cbc (CRToken *a_this) ;
|
||||
|
||||
enum CRStatus cr_token_set_cbo (CRToken *a_this) ;
|
||||
|
||||
enum CRStatus cr_token_set_semicolon (CRToken *a_this) ;
|
||||
|
||||
enum CRStatus cr_token_set_delim (CRToken *a_this, guint32 a_char) ;
|
||||
|
||||
|
||||
/*
|
||||
enum CRStatus
|
||||
cr_token_set_unicoderange (CRToken *a_this,
|
||||
CRUnicodeRange *a_range) ;
|
||||
*/
|
||||
|
||||
void
|
||||
cr_token_destroy (CRToken *a_this) ;
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /*__CR_TOKEN_H__*/
|
1330
src/st/croco/cr-utils.c
Normal file
1330
src/st/croco/cr-utils.c
Normal file
File diff suppressed because it is too large
Load Diff
246
src/st/croco/cr-utils.h
Normal file
246
src/st/croco/cr-utils.h
Normal file
@ -0,0 +1,246 @@
|
||||
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
|
||||
|
||||
/*
|
||||
* This file is part of The Croco Library
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of version 2.1 of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*
|
||||
* Author: Dodji Seketeli
|
||||
* Look at file COPYRIGHTS for copyright information
|
||||
*/
|
||||
|
||||
#ifndef __CR_DEFS_H__
|
||||
#define __CR_DEFS_H__
|
||||
|
||||
#include <stdio.h>
|
||||
#include <glib.h>
|
||||
#include "libcroco-config.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/**
|
||||
*@file
|
||||
*The Croco library basic types definitions
|
||||
*And global definitions.
|
||||
*/
|
||||
|
||||
/**
|
||||
*The status type returned
|
||||
*by the methods of the croco library.
|
||||
*/
|
||||
enum CRStatus {
|
||||
CR_OK,
|
||||
CR_BAD_PARAM_ERROR,
|
||||
CR_INSTANCIATION_FAILED_ERROR,
|
||||
CR_UNKNOWN_TYPE_ERROR,
|
||||
CR_UNKNOWN_PROP_ERROR,
|
||||
CR_UNKNOWN_PROP_VAL_ERROR,
|
||||
CR_UNEXPECTED_POSITION_SCHEME,
|
||||
CR_START_OF_INPUT_ERROR,
|
||||
CR_END_OF_INPUT_ERROR,
|
||||
CR_OUTPUT_TOO_SHORT_ERROR,
|
||||
CR_INPUT_TOO_SHORT_ERROR,
|
||||
CR_OUT_OF_BOUNDS_ERROR,
|
||||
CR_EMPTY_PARSER_INPUT_ERROR,
|
||||
CR_ENCODING_ERROR,
|
||||
CR_ENCODING_NOT_FOUND_ERROR,
|
||||
CR_PARSING_ERROR,
|
||||
CR_SYNTAX_ERROR,
|
||||
CR_NO_ROOT_NODE_ERROR,
|
||||
CR_NO_TOKEN,
|
||||
CR_OUT_OF_MEMORY_ERROR,
|
||||
CR_PSEUDO_CLASS_SEL_HANDLER_NOT_FOUND_ERROR,
|
||||
CR_BAD_PSEUDO_CLASS_SEL_HANDLER_ERROR,
|
||||
CR_ERROR,
|
||||
CR_FILE_NOT_FOUND_ERROR,
|
||||
CR_VALUE_NOT_FOUND_ERROR
|
||||
} ;
|
||||
|
||||
/**
|
||||
*Values used by
|
||||
*cr_input_seek_position() ;
|
||||
*/
|
||||
enum CRSeekPos {
|
||||
CR_SEEK_CUR,
|
||||
CR_SEEK_BEGIN,
|
||||
CR_SEEK_END
|
||||
} ;
|
||||
|
||||
/**
|
||||
*Encoding values.
|
||||
*/
|
||||
enum CREncoding
|
||||
{
|
||||
CR_UCS_4 = 1/*Must be not NULL*/,
|
||||
CR_UCS_1,
|
||||
CR_ISO_8859_1,
|
||||
CR_ASCII,
|
||||
CR_UTF_8,
|
||||
CR_UTF_16,
|
||||
CR_AUTO/*should be the last one*/
|
||||
} ;
|
||||
|
||||
|
||||
|
||||
|
||||
#define CROCO_LOG_DOMAIN "LIBCROCO"
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define cr_utils_trace(a_log_level, a_msg) \
|
||||
g_log (CROCO_LOG_DOMAIN, \
|
||||
G_LOG_LEVEL_CRITICAL, \
|
||||
"file %s: line %d (%s): %s\n", \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
__PRETTY_FUNCTION__, \
|
||||
a_msg)
|
||||
#else /*__GNUC__*/
|
||||
|
||||
#define cr_utils_trace(a_log_level, a_msg) \
|
||||
g_log (CROCO_LOG_DOMAIN, \
|
||||
G_LOG_LEVEL_CRITICAL, \
|
||||
"file %s: line %d: %s\n", \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
a_msg)
|
||||
#endif
|
||||
|
||||
/**
|
||||
*Traces an info message.
|
||||
*The file, line and enclosing function
|
||||
*of the message will be automatically
|
||||
*added to the message.
|
||||
*@param a_msg the msg to trace.
|
||||
*/
|
||||
#define cr_utils_trace_info(a_msg) \
|
||||
cr_utils_trace (G_LOG_LEVEL_INFO, a_msg)
|
||||
|
||||
/**
|
||||
*Trace a debug message.
|
||||
*The file, line and enclosing function
|
||||
*of the message will be automatically
|
||||
*added to the message.
|
||||
*@param a_msg the msg to trace.
|
||||
*/
|
||||
#define cr_utils_trace_debug(a_msg) \
|
||||
cr_utils_trace (G_LOG_LEVEL_DEBUG, a_msg) ;
|
||||
|
||||
|
||||
/****************************
|
||||
*Encoding transformations and
|
||||
*encoding helpers
|
||||
****************************/
|
||||
|
||||
enum CRStatus
|
||||
cr_utils_read_char_from_utf8_buf (const guchar * a_in, gulong a_in_len,
|
||||
guint32 *a_out, gulong *a_consumed) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_utils_ucs1_to_utf8 (const guchar *a_in, gulong *a_in_len,
|
||||
guchar *a_out, gulong *a_out_len) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_utils_utf8_to_ucs1 (const guchar * a_in, gulong * a_in_len,
|
||||
guchar *a_out, gulong *a_out_len) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_utils_ucs4_to_utf8 (const guint32 *a_in, gulong *a_in_len,
|
||||
guchar *a_out, gulong *a_out_len) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_utils_utf8_str_len_as_ucs4 (const guchar *a_in_start,
|
||||
const guchar *a_in_end,
|
||||
gulong *a_len) ;
|
||||
enum CRStatus
|
||||
cr_utils_ucs1_str_len_as_utf8 (const guchar *a_in_start,
|
||||
const guchar *a_in_end,
|
||||
gulong *a_len) ;
|
||||
enum CRStatus
|
||||
cr_utils_utf8_str_len_as_ucs1 (const guchar *a_in_start,
|
||||
const guchar *a_in_end,
|
||||
gulong *a_len) ;
|
||||
enum CRStatus
|
||||
cr_utils_ucs4_str_len_as_utf8 (const guint32 *a_in_start,
|
||||
const guint32 *a_in_end,
|
||||
gulong *a_len) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_utils_ucs1_str_to_utf8 (const guchar *a_in_start,
|
||||
gulong *a_in_len,
|
||||
guchar **a_out,
|
||||
gulong *a_len) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_utils_utf8_str_to_ucs1 (const guchar * a_in_start,
|
||||
gulong * a_in_len,
|
||||
guchar **a_out,
|
||||
gulong *a_out_len) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_utils_utf8_to_ucs4 (const guchar * a_in,
|
||||
gulong * a_in_len,
|
||||
guint32 *a_out, gulong *a_out_len) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_utils_ucs4_str_to_utf8 (const guint32 *a_in,
|
||||
gulong *a_in_len,
|
||||
guchar **a_out, gulong *a_out_len) ;
|
||||
|
||||
enum CRStatus
|
||||
cr_utils_utf8_str_to_ucs4 (const guchar * a_in,
|
||||
gulong *a_in_len,
|
||||
guint32 **a_out,
|
||||
gulong *a_out_len) ;
|
||||
|
||||
|
||||
/*****************************************
|
||||
*CSS basic types identification utilities
|
||||
*****************************************/
|
||||
|
||||
gboolean
|
||||
cr_utils_is_newline (guint32 a_char) ;
|
||||
|
||||
gboolean
|
||||
cr_utils_is_white_space (guint32 a_char) ;
|
||||
|
||||
gboolean
|
||||
cr_utils_is_nonascii (guint32 a_char) ;
|
||||
|
||||
gboolean
|
||||
cr_utils_is_hexa_char (guint32 a_char) ;
|
||||
|
||||
|
||||
/**********************************
|
||||
*Miscellaneous utility functions
|
||||
***********************************/
|
||||
|
||||
void
|
||||
cr_utils_dump_n_chars (guchar a_char,
|
||||
FILE *a_fp,
|
||||
glong a_nb) ;
|
||||
|
||||
void
|
||||
cr_utils_dump_n_chars2 (guchar a_char,
|
||||
GString *a_string,
|
||||
glong a_nb) ;
|
||||
GList *
|
||||
cr_utils_dup_glist_of_string (GList const *a_list) ;
|
||||
|
||||
GList *
|
||||
cr_utils_dup_glist_of_cr_string (GList const * a_list_of_strings) ;
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /*__CR_DEFS_H__*/
|
13
src/st/croco/libcroco-config.h
Normal file
13
src/st/croco/libcroco-config.h
Normal file
@ -0,0 +1,13 @@
|
||||
#ifndef LIBCROCO_VERSION_NUMBER
|
||||
#define LIBCROCO_VERSION_NUMBER 612
|
||||
#endif
|
||||
|
||||
#ifndef LIBCROCO_VERSION
|
||||
#define LIBCROCO_VERSION "0.6.12"
|
||||
#endif
|
||||
|
||||
#ifndef G_DISABLE_CHECKS
|
||||
#if 0
|
||||
#define G_DISABLE_CHECKS 0
|
||||
#endif
|
||||
#endif
|
42
src/st/croco/libcroco.h
Normal file
42
src/st/croco/libcroco.h
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* This file is part of The Croco Library
|
||||
*
|
||||
* Copyright (C) 2002-2003 Dodji Seketeli <dodji@seketeli.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of version 2.1 of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*/
|
||||
|
||||
#ifndef __LIBCROCO_H__
|
||||
#define __LIBCROCO_H__
|
||||
|
||||
#include "libcroco-config.h"
|
||||
|
||||
#include "cr-utils.h"
|
||||
#include "cr-pseudo.h"
|
||||
#include "cr-term.h"
|
||||
#include "cr-attr-sel.h"
|
||||
#include "cr-simple-sel.h"
|
||||
#include "cr-selector.h"
|
||||
#include "cr-enc-handler.h"
|
||||
#include "cr-doc-handler.h"
|
||||
#include "cr-input.h"
|
||||
#include "cr-parser.h"
|
||||
#include "cr-statement.h"
|
||||
#include "cr-stylesheet.h"
|
||||
#include "cr-om-parser.h"
|
||||
#include "cr-prop-list.h"
|
||||
#include "cr-string.h"
|
||||
|
||||
#endif /*__LIBCROCO_H__*/
|
@ -1,3 +1,4 @@
|
||||
# please, keep this sorted alphabetically
|
||||
st_headers = [
|
||||
'st-adjustment.h',
|
||||
'st-bin.h',
|
||||
@ -45,13 +46,68 @@ st_h = configure_file(
|
||||
|
||||
st_inc = include_directories('.', '..')
|
||||
|
||||
# please, keep this sorted alphabetically
|
||||
st_private_headers = [
|
||||
'croco/cr-additional-sel.h',
|
||||
'croco/cr-attr-sel.h',
|
||||
'croco/cr-cascade.h',
|
||||
'croco/cr-declaration.h',
|
||||
'croco/cr-doc-handler.h',
|
||||
'croco/cr-enc-handler.h',
|
||||
'croco/cr-fonts.h',
|
||||
'croco/cr-input.h',
|
||||
'croco/cr-num.h',
|
||||
'croco/cr-om-parser.h',
|
||||
'croco/cr-parser.h',
|
||||
'croco/cr-parsing-location.h',
|
||||
'croco/cr-prop-list.h',
|
||||
'croco/cr-pseudo.h',
|
||||
'croco/cr-rgb.h',
|
||||
'croco/cr-selector.h',
|
||||
'croco/cr-simple-sel.h',
|
||||
'croco/cr-statement.h',
|
||||
'croco/cr-string.h',
|
||||
'croco/cr-stylesheet.h',
|
||||
'croco/cr-term.h',
|
||||
'croco/cr-tknzr.h',
|
||||
'croco/cr-token.h',
|
||||
'croco/cr-utils.h',
|
||||
'croco/libcroco-config.h',
|
||||
'croco/libcroco.h',
|
||||
'st-private.h',
|
||||
'st-theme-private.h',
|
||||
'st-theme-node-private.h',
|
||||
'st-theme-node-transition.h'
|
||||
]
|
||||
|
||||
# please, keep this sorted alphabetically
|
||||
croco_sources = [
|
||||
'croco/cr-additional-sel.c',
|
||||
'croco/cr-attr-sel.c',
|
||||
'croco/cr-cascade.c',
|
||||
'croco/cr-declaration.c',
|
||||
'croco/cr-doc-handler.c',
|
||||
'croco/cr-enc-handler.c',
|
||||
'croco/cr-fonts.c',
|
||||
'croco/cr-input.c',
|
||||
'croco/cr-num.c',
|
||||
'croco/cr-om-parser.c',
|
||||
'croco/cr-parser.c',
|
||||
'croco/cr-parsing-location.c',
|
||||
'croco/cr-prop-list.c',
|
||||
'croco/cr-pseudo.c',
|
||||
'croco/cr-rgb.c',
|
||||
'croco/cr-selector.c',
|
||||
'croco/cr-simple-sel.c',
|
||||
'croco/cr-statement.c',
|
||||
'croco/cr-string.c',
|
||||
'croco/cr-stylesheet.c',
|
||||
'croco/cr-term.c',
|
||||
'croco/cr-tknzr.c',
|
||||
'croco/cr-token.c',
|
||||
'croco/cr-utils.c',
|
||||
]
|
||||
|
||||
# please, keep this sorted alphabetically
|
||||
st_sources = [
|
||||
'st-adjustment.c',
|
||||
@ -119,9 +175,9 @@ st_cflags = [
|
||||
|
||||
# Currently meson requires a shared library for building girs
|
||||
libst = shared_library('st-1.0',
|
||||
sources: st_gir_sources,
|
||||
sources: st_gir_sources + croco_sources,
|
||||
c_args: st_cflags,
|
||||
dependencies: [clutter_dep, gtk_dep, croco_dep, mutter_dep, m_dep],
|
||||
dependencies: [clutter_dep, gtk_dep, mutter_dep, libxml_dep, m_dep],
|
||||
build_rpath: mutter_typelibdir,
|
||||
install_rpath: mutter_typelibdir,
|
||||
install_dir: pkglibdir,
|
||||
@ -135,7 +191,7 @@ libst_dep = declare_dependency(link_with: libst,
|
||||
test_theme = executable('test-theme',
|
||||
sources: 'test-theme.c',
|
||||
c_args: st_cflags,
|
||||
dependencies: [mutter_dep, gtk_dep],
|
||||
dependencies: [mutter_dep, gtk_dep, libxml_dep],
|
||||
build_rpath: mutter_typelibdir,
|
||||
link_with: libst
|
||||
)
|
||||
|
@ -25,7 +25,7 @@
|
||||
#include <gdk/gdk.h>
|
||||
|
||||
#include "st-theme-node.h"
|
||||
#include <libcroco/libcroco.h>
|
||||
#include "croco/libcroco.h"
|
||||
#include "st-types.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
@ -21,7 +21,7 @@
|
||||
#ifndef __ST_THEME_PRIVATE_H__
|
||||
#define __ST_THEME_PRIVATE_H__
|
||||
|
||||
#include <libcroco/libcroco.h>
|
||||
#include "croco/libcroco.h"
|
||||
#include "st-theme.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
Loading…
Reference in New Issue
Block a user