Author: fejj
Date: 2007-06-13 19:11:25 -0400 (Wed, 13 Jun 2007)
New Revision: 79524
Modified:
trunk/moon/src/ChangeLog
trunk/moon/src/Makefile.am
trunk/moon/src/media.cpp
trunk/moon/src/media.h
trunk/moon/src/runtime.cpp
trunk/moon/src/text.cpp
trunk/moon/src/text.h
Log:
2007-06-13 Jeffrey Stedfast <[EMAIL PROTECTED]>
* text.cpp: Implemented a ton of stuff...
(text_init): Added.
* runtime.cpp (runtime_init): Call text_init().
Modified: trunk/moon/src/ChangeLog
===================================================================
--- trunk/moon/src/ChangeLog 2007-06-13 22:55:52 UTC (rev 79523)
+++ trunk/moon/src/ChangeLog 2007-06-13 23:11:25 UTC (rev 79524)
@@ -1,3 +1,10 @@
+2007-06-13 Jeffrey Stedfast <[EMAIL PROTECTED]>
+
+ * text.cpp: Implemented a ton of stuff...
+ (text_init): Added.
+
+ * runtime.cpp (runtime_init): Call text_init().
+
2007-06-13 Miguel de Icaza <[EMAIL PROTECTED]>
* runtime.cpp (SetValue): Enable NULLs to be set on Dependency
Modified: trunk/moon/src/Makefile.am
===================================================================
--- trunk/moon/src/Makefile.am 2007-06-13 22:55:52 UTC (rev 79523)
+++ trunk/moon/src/Makefile.am 2007-06-13 23:11:25 UTC (rev 79524)
@@ -25,6 +25,7 @@
shape.cpp \
shape.h \
text.cpp \
+ text.h \
transform.cpp \
transform.h \
type.cpp \
Modified: trunk/moon/src/media.cpp
===================================================================
--- trunk/moon/src/media.cpp 2007-06-13 22:55:52 UTC (rev 79523)
+++ trunk/moon/src/media.cpp 2007-06-13 23:11:25 UTC (rev 79524)
@@ -21,7 +21,6 @@
DependencyProperty *MediaBase::SourceProperty;
DependencyProperty *MediaBase::StretchProperty;
-
char *
media_base_get_source (MediaBase *media)
{
@@ -92,7 +91,6 @@
;
}
-
bool
media_element_get_auto_play (MediaElement *media)
{
Modified: trunk/moon/src/media.h
===================================================================
--- trunk/moon/src/media.h 2007-06-13 22:55:52 UTC (rev 79523)
+++ trunk/moon/src/media.h 2007-06-13 23:11:25 UTC (rev 79524)
@@ -8,6 +8,16 @@
#include "clock.h"
#include "value.h"
+
+class MediaAttribute : public DependencyObject {
+ public:
+ static DependencyProperty *ValueProperty;
+
+ MediaAttribute () { }
+ Value::Kind GetObjectType () { return Value::MEDIAATTRIBUTE; };
+};
+
+
class MediaBase : public FrameworkElement {
public:
static DependencyProperty *SourceProperty;
@@ -54,14 +64,6 @@
void Stop ();
};
-class MediaAttribute : public DependencyObject {
- public:
- static DependencyProperty *ValueProperty;
-
- MediaAttribute () { }
- Value::Kind GetObjectType () { return Value::MEDIAATTRIBUTE; };
-};
-
bool media_element_get_auto_play (MediaElement *media);
void media_element_set_auto_play (MediaElement *media, bool value);
Modified: trunk/moon/src/runtime.cpp
===================================================================
--- trunk/moon/src/runtime.cpp 2007-06-13 22:55:52 UTC (rev 79523)
+++ trunk/moon/src/runtime.cpp 2007-06-13 23:11:25 UTC (rev 79524)
@@ -30,6 +30,7 @@
#include "shape.h"
#include "transform.h"
#include "animation.h"
+#include "text.h"
#if AGG
struct _SurfacePrivate {
@@ -2082,6 +2083,7 @@
geometry_init ();
xaml_init ();
clock_init ();
+ text_init ();
}
void surface_register_events (Surface *s,
Modified: trunk/moon/src/text.cpp
===================================================================
--- trunk/moon/src/text.cpp 2007-06-13 22:55:52 UTC (rev 79523)
+++ trunk/moon/src/text.cpp 2007-06-13 23:11:25 UTC (rev 79524)
@@ -13,12 +13,71 @@
#endif
#include <gtk/gtk.h>
+#include <pango/pango.h>
+#include <cairo.h>
#include <string.h>
+#include "cutil.h"
#include "text.h"
+static PangoStretch
+get_pango_stretch (FontStretches stretch)
+{
+ switch (stretch) {
+ case FontStretchesUltraCondensed:
+ return PANGO_STRETCH_ULTRA_CONDENSED;
+ case FontStretchesExtraCondensed:
+ return PANGO_STRETCH_EXTRA_CONDENSED;
+ case FontStretchesCondensed:
+ return PANGO_STRETCH_CONDENSED;
+ case FontStretchesSemiCondensed:
+ return PANGO_STRETCH_SEMI_CONDENSED;
+ case FontStretchesNormal:
+ case FontStretchesMedium: // alias for FontStretchesNormal
+ default:
+ return PANGO_STRETCH_NORMAL;
+ case FontStretchesSemiExpanded:
+ return PANGO_STRETCH_SEMI_EXPANDED;
+ case FontStretchesExpanded:
+ return PANGO_STRETCH_EXPANDED;
+ case FontStretchesExtraExpanded:
+ return PANGO_STRETCH_EXTRA_EXPANDED;
+ case FontStretchesUltraExpanded:
+ return PANGO_STRETCH_ULTRA_EXPANDED;
+ }
+}
+
+static PangoStyle
+get_pango_style (FontStyles style)
+{
+ switch (style) {
+ case FontStylesNormal:
+ default:
+ return PANGO_STYLE_NORMAL;
+ case FontStylesOblique:
+ return PANGO_STYLE_OBLIQUE;
+ case FontStylesItalic:
+ return PANGO_STYLE_ITALIC;
+ }
+}
+
+static PangoWeight
+get_pango_weight (FontWeights weight)
+{
+ // FontWeights and PangoWeight values map exactly
+
+ if (weight > 900) {
+ // FontWeighs have values between 100-999, Pango only allows
100-900
+ return (PangoWeight) 900;
+ }
+
+ return (PangoWeight) weight;
+}
+
+
+
// Inline
DependencyProperty *Inline::FontFamilyProperty;
@@ -135,6 +194,104 @@
;
}
+void
+TextBlock::render (Surface *s, int x, int y, int width, int height)
+{
+ cairo_save (s->cairo);
+ Draw (s, true);
+ cairo_restore (s->cairo);
+}
+
+void
+TextBlock::getbounds ()
+{
+ Surface *s = item_get_surface (this);
+
+ // not yet attached
+ if (s == NULL)
+ return;
+
+ cairo_save (s->cairo);
+
+ Draw (s, false);
+
+ cairo_stroke_extents (s->cairo, &x1, &y1, &x2, &y2);
+ cairo_new_path (s->cairo);
+ cairo_restore (s->cairo);
+
+ // The extents are in the coordinates of the transform, translate to
device coordinates
+ x_cairo_matrix_transform_bounding_box (&absolute_xform, &x1, &y1, &x2,
&y2);
+}
+
+bool
+TextBlock::inside_object (Surface *s, double x, double y)
+{
+ bool ret = false;
+
+ cairo_save (s->cairo);
+
+ Draw (s, false);
+
+ double nx = x;
+ double ny = y;
+
+ cairo_matrix_t inverse = absolute_xform;
+ cairo_matrix_invert (&inverse);
+
+ cairo_matrix_transform_point (&inverse, &nx, &ny);
+
+ if (cairo_in_stroke (s->cairo, nx, ny) || cairo_in_fill (s->cairo, nx,
ny))
+ ret = true;
+
+ cairo_new_path (s->cairo);
+
+ cairo_restore (s->cairo);
+
+ return ret;
+}
+
+void
+TextBlock::Draw (Surface *s, bool render)
+{
+ PangoFontDescription *font = NULL;
+ PangoLayout *layout = NULL;
+ char *family, *text;
+ FontStretches stretch;
+ FontWeights weight;
+ FontStyles style;
+ double size;
+ Brush *brush;
+
+ cairo_set_matrix (s->cairo, &absolute_xform);
+
+ if ((text = textblock_get_text (this)) != NULL) {
+ if (!layout)
+ layout = pango_cairo_create_layout (s->cairo);
+
+ family = textblock_get_font_family (this);
+ stretch = textblock_get_font_stretch (this);
+ weight = textblock_get_font_weight (this);
+ style = textblock_get_font_style (this);
+ size = textblock_get_font_size (this);
+
+ brush = textblock_get_foreground (this);
+
+ // FIXME: cache the PangoFontDescription
+ font = pango_font_description_new ();
+ pango_font_description_set_family (font, family);
+ pango_font_description_set_stretch (font, get_pango_stretch
(stretch));
+ pango_font_description_set_weight (font, get_pango_weight
(weight));
+ pango_font_description_set_style (font, get_pango_style
(style));
+ pango_font_description_set_absolute_size (font, size);
+
+ pango_layout_set_font_description (layout, font);
+ pango_layout_set_text (layout, text, -1);
+
+ //pango_cairo_update_layout (cr, layout);
+ pango_cairo_show_layout (s->cairo, layout);
+ }
+}
+
double
textblock_get_actual_height (TextBlock *textblock)
{
@@ -386,3 +543,42 @@
{
glyphs->SetValue (Glyphs::UnicodeStringProperty, Value (value));
}
+
+
+
+void
+text_init (void)
+{
+ // Inline
+ Inline::FontFamilyProperty = DependencyObject::Register (Value::INLINE,
"FontFamily", Value::STRING);
+ Inline::FontSizeProperty = DependencyObject::Register (Value::INLINE,
"FontSize", Value::DOUBLE);
+ Inline::FontStretchProperty = DependencyObject::Register
(Value::INLINE, "FontStretch", new Value (FontStretchesNormal));
+ Inline::FontStyleProperty = DependencyObject::Register (Value::INLINE,
"FontStyle", new Value (FontStylesNormal));
+ Inline::FontWeightProperty = DependencyObject::Register (Value::INLINE,
"FontWeight", new Value (FontWeightsNormal));
+ Inline::ForegroundProperty = DependencyObject::Register (Value::INLINE,
"Foreground", Value::BRUSH);
+ Inline::TextDecorationsProperty = DependencyObject::Register
(Value::INLINE, "TextDecorations", new Value (TextDecorationsNone));
+
+ // TextBlock
+ TextBlock::ActualHeightProperty = DependencyObject::Register
(Value::TEXTBLOCK, "ActualHeight", Value::DOUBLE);
+ TextBlock::ActualWidthProperty = DependencyObject::Register
(Value::TEXTBLOCK, "ActualWidth", Value::DOUBLE);
+ TextBlock::FontFamilyProperty = DependencyObject::Register
(Value::TEXTBLOCK, "FontFamily", Value::STRING);
+ TextBlock::FontSizeProperty = DependencyObject::Register
(Value::TEXTBLOCK, "FontSize", Value::DOUBLE);
+ TextBlock::FontStretchProperty = DependencyObject::Register
(Value::TEXTBLOCK, "FontStretch", new Value (FontStretchesNormal));
+ TextBlock::FontStyleProperty = DependencyObject::Register
(Value::TEXTBLOCK, "FontStyle", new Value (FontStylesNormal));
+ TextBlock::FontWeightProperty = DependencyObject::Register
(Value::TEXTBLOCK, "FontWeight", new Value (FontWeightsNormal));
+ TextBlock::ForegroundProperty = DependencyObject::Register
(Value::TEXTBLOCK, "Foreground", Value::BRUSH);
+ TextBlock::InlinesProperty = DependencyObject::Register
(Value::TEXTBLOCK, "Inlines", Value::INLINES);
+ TextBlock::TextProperty = DependencyObject::Register (Value::TEXTBLOCK,
"Text", Value::STRING);
+ TextBlock::TextDecorationsProperty = DependencyObject::Register
(Value::TEXTBLOCK, "TextDecorations", new Value (TextDecorationsNone));
+ TextBlock::TextWrappingProperty = DependencyObject::Register
(Value::TEXTBLOCK, "TextWrapping", new Value (TextWrappingNoWrap));
+
+ // Glyphs
+ Glyphs::FillProperty = DependencyObject::Register (Value::GLYPHS,
"Fill", Value::BRUSH);
+ Glyphs::FontRenderingEmSizeProperty = DependencyObject::Register
(Value::GLYPHS, "FontRenderingEmSize", Value::DOUBLE);
+ Glyphs::FontUriProperty = DependencyObject::Register (Value::GLYPHS,
"FontUri", Value::STRING);
+ Glyphs::IndicesProperty = DependencyObject::Register (Value::GLYPHS,
"Indices", Value::STRING);
+ Glyphs::OriginXProperty = DependencyObject::Register (Value::GLYPHS,
"OriginX", Value::DOUBLE);
+ Glyphs::OriginYProperty = DependencyObject::Register (Value::GLYPHS,
"OriginY", Value::DOUBLE);
+ Glyphs::StyleSimulationsProperty = DependencyObject::Register
(Value::GLYPHS, "StyleSimulations", Value::STRING);
+ Glyphs::UnicodeStringProperty = DependencyObject::Register
(Value::GLYPHS, "UnicodeString", Value::STRING);
+}
Modified: trunk/moon/src/text.h
===================================================================
--- trunk/moon/src/text.h 2007-06-13 22:55:52 UTC (rev 79523)
+++ trunk/moon/src/text.h 2007-06-13 23:11:25 UTC (rev 79524)
@@ -55,6 +55,8 @@
TextWrappingWrapWithOverflow
};
+void text_init (void);
+
class Inline : public DependencyObject {
public:
static DependencyProperty *FontFamilyProperty;
@@ -110,6 +112,16 @@
Value::Kind GetObjectType () { return Value::TEXTBLOCK; };
void SetFontSource (DependencyObject *downloader);
+
+ //
+ // Overrides from UIElement.
+ //
+ virtual void render (Surface *s, int x, int y, int width, int height);
+ virtual void getbounds ();
+ virtual bool inside_object (Surface *s, double x, double y);
+
+private:
+ void Draw (Surface *s, bool render);
};
double textblock_get_actual_height (TextBlock *textblock);
@@ -148,6 +160,7 @@
TextWrapping textblock_get_text_wrapping (TextBlock *textblock);
void textblock_set_text_wrapping (TextBlock *textblock, TextWrapping value);
+
class Glyphs : public FrameworkElement {
public:
static DependencyProperty *FillProperty;
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches