#include "ATSUnicode.h"
#include "TextCommon.h"
#include "TextEncodingConverter.h"
+#include "FixMath.h"
#if !USE_SHARED_LIBRARY
IMPLEMENT_ABSTRACT_CLASS(wxDC, wxObject)
#endif
#define mm2pt 2.83464566929
#define pt2mm 0.352777777778
#if !defined( __DARWIN__ ) || defined(__MWERKS__)
+#ifndef M_PI
const double M_PI = 3.14159265358979 ;
#endif
+#endif
const double RAD2DEG = 180.0 / M_PI;
const short kEmulatedMode = -1 ;
const short kUnsupportedMode = -2 ;
void wxDC::DoSetClippingRegionAsRegion( const wxRegion ®ion )
{
wxCHECK_RET( Ok(), wxT("invalid window dc") ) ;
- wxMacPortSetter helper(this) ;
if (region.Empty())
{
DestroyClippingRegion();
return;
}
+ wxMacPortSetter helper(this) ;
wxCoord x, y, w, h;
region.GetBox( x, y, w, h );
wxCoord xx, yy, ww, hh;
return TRUE;
}
+#ifndef FixedToInt
+// as macro in FixMath.h for 10.3
inline Fixed IntToFixed( int inInt )
{
return (((SInt32) inInt) << 16);
{
return (((SInt32) inFixed) >> 16);
}
+#endif
void wxDC::DoDrawRotatedText(const wxString& str, wxCoord x, wxCoord y,
double angle)
&chars , (ATSUStyle*) &m_macATSUIStyle , &atsuLayout ) ;
#else
TECObjectRef ec;
- status = TECCreateConverter(&ec,
- wxApp::s_macDefaultEncodingIsPC ? kTextEncodingWindowsLatin1 : kTextEncodingMacRoman, kTextEncodingUnicodeDefault);
-
+ status = TECCreateConverter(&ec,
+ wxApp::s_macDefaultEncodingIsPC
+ ? (int)kTextEncodingWindowsLatin1
+ : (int)kTextEncodingMacRoman,
+ kTextEncodingUnicodeDefault);
+
wxASSERT_MSG( status == noErr , wxT("couldn't start converter") ) ;
ByteCount byteOutLen ;
ByteCount byteInLen = str.Length() ;
status = ::ATSUMeasureText( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd,
&textBefore , &textAfter, &ascent , &descent );
- drawX += sin(angle/RAD2DEG) * FixedToInt(ascent) ;
- drawY += cos(angle/RAD2DEG) * FixedToInt(ascent) ;
+ drawX += (int)(sin(angle/RAD2DEG) * FixedToInt(ascent));
+ drawY += (int)(cos(angle/RAD2DEG) * FixedToInt(ascent));
status = ::ATSUDrawText( atsuLayout, kATSUFromTextBeginning, kATSUToTextEnd,
IntToFixed(drawX) , IntToFixed(drawY) );
wxASSERT_MSG( status == noErr , wxT("couldn't draw the rotated text") );
{
if( strtext[i] == 13 || strtext[i] == 10)
{
- wxString linetext = strtext.Mid( laststop , i - laststop ) ;
+ wxString linetext = strtext.Mid( laststop , i - laststop ) ;
#if TARGET_CARBON
if ( useDrawThemeText )
{
else
#endif
{
- wxCharBuffer text = wxMacStringToCString(linetext) ;
+ wxCharBuffer text = wxMacStringToCString(linetext) ;
::DrawText( text , 0 , strlen(text) ) ;
line++ ;
::MoveTo( xx , yy + line*(fi.descent + fi.ascent + fi.leading) );
else
#endif
{
- wxCharBuffer text = wxMacStringToCString(linetext) ;
+ wxCharBuffer text = wxMacStringToCString(linetext) ;
::DrawText( text , 0 , strlen(text) ) ;
}
}
::GetFontInfo( &fi ) ;
#if TARGET_CARBON
bool useGetThemeText = ( GetThemeTextDimensions != (void*) kUnresolvedCFragSymbolAddress ) ;
- if ( IsKindOf(CLASSINFO( wxPrinterDC ) ) || ((wxFont*)&m_font)->GetNoAntiAliasing() )
+ if ( IsKindOf(CLASSINFO( wxPrinterDC ) ) || ((wxFont*)&m_font)->GetNoAntiAliasing() )
useGetThemeText = false ;
#endif
if ( height )
{
if( strtext[i] == 13 || strtext[i] == 10)
{
- wxString linetext = strtext.Mid( laststop , i - laststop ) ;
+ wxString linetext = strtext.Mid( laststop , i - laststop ) ;
if ( height )
*height += YDEV2LOGREL( fi.descent + fi.ascent + fi.leading ) ;
#if TARGET_CARBON
else
#endif
{
- wxCharBuffer text = wxMacStringToCString(linetext) ;
- curwidth = ::TextWidth( text , 0 , strlen(text) ) ;
+ wxCharBuffer text = wxMacStringToCString(linetext) ;
+ curwidth = ::TextWidth( text , 0 , strlen(text) ) ;
}
if ( curwidth > *width )
*width = XDEV2LOGREL( curwidth ) ;
else
#endif
{
- wxCharBuffer text = wxMacStringToCString(linetext) ;
+ wxCharBuffer text = wxMacStringToCString(linetext) ;
curwidth = ::TextWidth( text , 0 , strlen(text) ) ;
}
if ( curwidth > *width )
Fixed atsuSize = IntToFixed( int(m_scaleY * font->m_macFontSize) ) ;
Style qdStyle = font->m_macFontStyle ;
ATSUFontID atsuFont = font->m_macATSUFontID ;
- status = ::ATSUCreateStyle(&(ATSUStyle)m_macATSUIStyle) ;
+ status = ::ATSUCreateStyle((ATSUStyle *)&m_macATSUIStyle) ;
wxASSERT_MSG( status == noErr , wxT("couldn't create ATSU style") ) ;
ATSUAttributeTag atsuTags[] =
{
} ;
Boolean kTrue = true ;
Boolean kFalse = false ;
- BslnBaselineClass kBaselineDefault = kBSLNHangingBaseline ;
+ //BslnBaselineClass kBaselineDefault = kBSLNHangingBaseline ;
ATSUVerticalCharacterType kHorizontal = kATSUStronglyHorizontal;
ATSUAttributeValuePtr atsuValues[sizeof(atsuTags)/sizeof(ATSUAttributeTag)] =
{
wxASSERT_MSG( status == noErr , wxT("couldn't set create ATSU style") ) ;
}
-Pattern gHatchPatterns[] =
-{
- { { 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF } },
- { { 0x01 , 0x02 , 0x04 , 0x08 , 0x10 , 0x20 , 0x40 , 0x80 } },
- { { 0x80 , 0x40 , 0x20 , 0x10 , 0x08 , 0x04 , 0x02 , 0x01 } },
- { { 0x10 , 0x10 , 0x10 , 0xFF , 0x10 , 0x10 , 0x10 , 0x10 } },
- { { 0x00 , 0x00 , 0x00 , 0xFF , 0x00 , 0x00 , 0x00 , 0x00 } },
- { { 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 } },
- { { 0x81 , 0x42 , 0x24 , 0x18 , 0x18 , 0x24 , 0x42 , 0x81 } }
+Pattern gPatterns[] =
+{ // hatch patterns
+ { 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF } ,
+ { 0x01 , 0x02 , 0x04 , 0x08 , 0x10 , 0x20 , 0x40 , 0x80 } ,
+ { 0x80 , 0x40 , 0x20 , 0x10 , 0x08 , 0x04 , 0x02 , 0x01 } ,
+ { 0x10 , 0x10 , 0x10 , 0xFF , 0x10 , 0x10 , 0x10 , 0x10 } ,
+ { 0x00 , 0x00 , 0x00 , 0xFF , 0x00 , 0x00 , 0x00 , 0x00 } ,
+ { 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 } ,
+ { 0x81 , 0x42 , 0x24 , 0x18 , 0x18 , 0x24 , 0x42 , 0x81 } ,
+ // dash patterns
+ { 0xCC , 0x99 , 0x33 , 0x66 , 0xCC , 0x99 , 0x33 , 0x66 } , // DOT
+ { 0xFE , 0xFD , 0xFB , 0xF7 , 0xEF , 0xDF , 0xBF , 0x7F } , // LONG_DASH
+ { 0xEE , 0xDD , 0xBB , 0x77 , 0xEE , 0xDD , 0xBB , 0x77 } , // SHORT_DASH
+ { 0xDE , 0xBD , 0x7B , 0xF6 , 0xED , 0xDB , 0xB7 , 0x6F } , // DOT_DASH
} ;
-static void wxMacGetHatchPattern(int hatchStyle, Pattern *pattern)
+static void wxMacGetPattern(int penStyle, Pattern *pattern)
{
- int theIndex = 1 ;
- switch(hatchStyle)
- {
- case wxBDIAGONAL_HATCH:
- theIndex = 2;
- break;
- case wxFDIAGONAL_HATCH:
- theIndex = 3;
- break;
- case wxCROSS_HATCH:
- theIndex = 4;
- break;
- case wxHORIZONTAL_HATCH:
- theIndex = 5;
- break;
- case wxVERTICAL_HATCH:
- theIndex = 6;
- break;
- case wxCROSSDIAG_HATCH:
- theIndex = 7;
- break;
- default:
- theIndex = 1; // solid pattern
- break;
+ int index = 0; // solid pattern by default
+ switch(penStyle)
+ {
+ // hatches
+ case wxBDIAGONAL_HATCH: index = 1; break;
+ case wxFDIAGONAL_HATCH: index = 2; break;
+ case wxCROSS_HATCH: index = 3; break;
+ case wxHORIZONTAL_HATCH: index = 4; break;
+ case wxVERTICAL_HATCH: index = 5; break;
+ case wxCROSSDIAG_HATCH: index = 6; break;
+ // dashes
+ case wxDOT: index = 7; break;
+ case wxLONG_DASH: index = 8; break;
+ case wxSHORT_DASH: index = 9; break;
+ case wxDOT_DASH: index = 10; break;
}
- *pattern = gHatchPatterns[theIndex-1] ;
+ *pattern = gPatterns[index];
}
void wxDC::MacInstallPen() const
::RGBForeColor( &forecolor );
::RGBBackColor( &backcolor );
::PenNormal() ;
- int penWidth = m_pen.GetWidth() * (int) m_scaleX ;
+ int penWidth = (int) (m_pen.GetWidth() * m_scaleX) ; ;
// null means only one pixel, at whatever resolution
if ( penWidth == 0 )
penWidth = 1 ;
::PenSize(penWidth, penWidth);
+
int penStyle = m_pen.GetStyle();
- if (penStyle == wxSOLID)
- {
- ::PenPat(GetQDGlobalsBlack(&blackColor));
- }
- else if (IS_HATCH(penStyle))
- {
- Pattern pat ;
- wxMacGetHatchPattern(penStyle, &pat);
- ::PenPat(&pat);
+ Pattern pat;
+ if (penStyle == wxUSER_DASH)
+ {
+ // FIXME: there should be exactly 8 items in the dash
+ wxDash* dash ;
+ int number = m_pen.GetDashes(&dash) ;
+ int index = 0;
+ for ( int i = 0 ; i < 8 ; ++i )
+ {
+ pat.pat[i] = dash[index] ;
+ if (index < number - 1)
+ index++;
+ }
}
else
{
- Pattern pat = *GetQDGlobalsBlack(&blackColor) ;
- switch( penStyle )
- {
- case wxDOT :
- for ( int i = 0 ; i < 8 ; ++i )
- {
- pat.pat[i] = 0xCC ;
- }
- break ;
- case wxLONG_DASH :
- for ( int i = 0 ; i < 8 ; ++i )
- {
- pat.pat[i] = 0xFE ;
- }
- break ;
- case wxSHORT_DASH :
- for ( int i = 0 ; i < 8 ; ++i )
- {
- pat.pat[i] = 0xEE ;
- }
- break ;
- case wxDOT_DASH :
- for ( int i = 0 ; i < 8 ; ++i )
- {
- pat.pat[i] = 0x6F ;
- }
- break ;
- case wxUSER_DASH :
- {
- wxDash* dash ;
- m_pen.GetDashes(&dash) ;
- // right now we don't allocate larger pixmaps
- // int number =
- m_pen.GetDashes(&dash) ;
- for ( int i = 0 ; i < 8 ; ++i )
- {
- pat.pat[i] = dash[0] ;
- }
- }
- break ;
- }
- ::PenPat(&pat);
+ wxMacGetPattern(penStyle, &pat);
}
+ ::PenPat(&pat);
+
short mode = patCopy ;
// todo :
switch( m_logicalFunction )
Pattern whiteColor ;
switch( background.MacGetBrushKind() )
{
- case kwxMacBrushTheme :
+ case kwxMacBrushTheme :
{
::SetThemeBackground( background.GetMacTheme() , wxDisplayDepth() , true ) ;
break ;
}
- case kwxMacBrushThemeBackground :
+ case kwxMacBrushThemeBackground :
{
Rect extent ;
ThemeBackgroundKind bg = background.GetMacThemeBackground( &extent ) ;
::ApplyThemeBackground( bg , &extent ,kThemeStateActive , wxDisplayDepth() , true ) ;
break ;
}
- case kwxMacBrushColour :
+ case kwxMacBrushColour :
{
- ::RGBBackColor( &MAC_WXCOLORREF( background.GetColour().GetPixel()) );
+ ::RGBBackColor( &MAC_WXCOLORREF( background.GetColour().GetPixel()) );
int brushStyle = background.GetStyle();
if (brushStyle == wxSOLID)
::BackPat(GetQDGlobalsWhite(&whiteColor));
else if (IS_HATCH(brushStyle))
{
Pattern pat ;
- wxMacGetHatchPattern(brushStyle, &pat);
+ wxMacGetPattern(brushStyle, &pat);
::BackPat(&pat);
}
else
else if (IS_HATCH(brushStyle))
{
Pattern pat ;
- wxMacGetHatchPattern(brushStyle, &pat);
+ wxMacGetPattern(brushStyle, &pat);
::PenPat(&pat);
}
else if ( m_brush.GetStyle() == wxSTIPPLE || m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE )