Imported Upstream version 3.10.0

Former-commit-id: 172c8e3c300b39d5785c7a3e8dfb08ebdbc1a99b
This commit is contained in:
Jo Shields
2014-10-04 11:27:48 +01:00
parent fe777c5c82
commit 8b9b85e7f5
970 changed files with 20242 additions and 31308 deletions

View File

@@ -1,89 +0,0 @@
//
// System.Drawing.Text.FontCollection.cs
//
// (C) 2002 Ximian, Inc. http://www.ximian.com
// Author: Everaldo Canuto everaldo.canuto@bol.com.br
// Sanjay Gupta (gsanjay@novell.com)
//
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.Collections.Specialized;
using awt = java.awt;
namespace System.Drawing.Text
{
/// <summary>
/// Summary description for FontCollection.
/// </summary>
public abstract class FontCollection : IDisposable
{
private readonly Hashtable _fonts;
protected FontCollection()
{
_fonts = CollectionsUtil.CreateCaseInsensitiveHashtable( new Hashtable() );
}
protected FontCollection(Hashtable fonts) {
_fonts = fonts;
}
public FontFamily[] Families {
get {
ICollection values = _fonts.Keys;
FontFamily[] families = new FontFamily[values.Count];
string [] keys = new string[_fonts.Count];
_fonts.Keys.CopyTo(keys, 0);
for (int i = 0; i < _fonts.Count; i++)
families[i] = new FontFamily( keys[i] );
return families;
}
}
internal virtual awt.Font GetInitialFont(string familyName) {
return (awt.Font)_fonts[familyName];
}
internal virtual bool Contains(string familyName) {
return _fonts.ContainsKey( familyName );
}
protected void AddFont(awt.Font font) {
_fonts.Add(font.getFamily(), font);
}
#region IDisposable Members
public void Dispose() {
// TODO: Add FontCollection.Dispose implementation
}
#endregion
}
}

View File

@@ -1,57 +0,0 @@
//
// System.Drawing.InstalledFontCollection.cs
//
// (C) 2005 Mainsoft Corporation (http://www.mainsoft.com)
// Author: Konstantin Triger (kostat@mainsoft.com)
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.Collections.Specialized;
using awt = java.awt;
namespace System.Drawing.Text
{
/// <summary>
/// Summary description for InstalledFontCollection.
/// </summary>
public sealed class InstalledFontCollection : FontCollection
{
static readonly Hashtable _installedFonts;
static InstalledFontCollection()
{
_installedFonts = CollectionsUtil.CreateCaseInsensitiveHashtable( new Hashtable() );
java.awt.Font [] fonts = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
for (int i = 0; i < fonts.Length; i++) {
string fontFamilyName = fonts[i].getFamily();
if (!_installedFonts.ContainsKey( fontFamilyName ))
_installedFonts.Add(fontFamilyName, fonts[i]);
}
}
public InstalledFontCollection() : base( _installedFonts ) {
}
}
}

View File

@@ -1,193 +0,0 @@
//
// System.Drawing.Test.LineLayout.jvm.cs
//
// Author:
// Konstantin Triger <kostat@mainsoft.com>
//
// Copyright (C) 2005 Mainsoft Corporation, (http://www.mainsoft.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Drawing.Drawing2D;
using font = java.awt.font;
using text = java.text;
using awt = java.awt;
using geom = java.awt.geom;
namespace System.Drawing.Text {
internal sealed class LineLayout {
#region Fields
readonly font.TextLayout _layout;
readonly float _accumulatedHeight;
readonly TextLineIterator _lineIter;
#endregion
#region ctor
internal LineLayout(font.TextLayout layout,
TextLineIterator lineIter,
float accumulatedHeight) {
_layout = layout;
_lineIter = lineIter;
_accumulatedHeight = accumulatedHeight;
}
#endregion
#region Properties
internal float AccumulatedHeight {
get { return _accumulatedHeight; }
}
internal float MeasureWidth {
get {
return _lineIter.PadWidth (Width);
}
}
internal float WidthPadding {
get {
return _lineIter.PadWidth (Width) - Width;
}
}
internal int CharacterCount {
get { return _layout.getCharacterCount(); }
}
internal float Ascent {
get { return _layout.getAscent(); }
}
internal float Descent {
get { return _layout.getDescent(); }
}
public float Leading {
get { return _layout.getLeading(); }
}
internal float NativeY {
get {
if (_lineIter.Format.IsVertical) {
float height = _lineIter.Height;
if (float.IsPositiveInfinity(height))
height = 0;
switch (_lineIter.Format.Alignment) {
case StringAlignment.Center:
return (height - Width) / 2;
case StringAlignment.Far:
return height - _layout.getVisibleAdvance () - WidthPadding;
default:
return WidthPadding;
}
}
else
return AccumulatedHeight + Ascent;
}
}
internal float NativeX {
get {
float width = _lineIter.Width;
if (float.IsPositiveInfinity(width))
width = 0;
if (_lineIter.Format.IsVertical)
return (_lineIter.Format.IsRightToLeft) ?
width - AccumulatedHeight - Ascent :
AccumulatedHeight + Leading + Descent;
else {
float xOffset;
switch ( _lineIter.Format.Alignment) {
case StringAlignment.Center:
xOffset = (width - Width) / 2;
break;
case StringAlignment.Far:
if (_lineIter.Format.IsRightToLeft)
xOffset = WidthPadding/2;
else
xOffset = width - _layout.getVisibleAdvance () - WidthPadding/2;
break;
default:
if (_lineIter.Format.IsRightToLeft)
xOffset = width - _layout.getVisibleAdvance () - WidthPadding/2;
else
xOffset = WidthPadding / 2;
break;
}
return xOffset;
}
}
}
internal float Height {
get {
return Ascent + Descent + Leading;
}
}
internal float Width {
get {
if (_lineIter.Format.MeasureTrailingSpaces)
if (!(_lineIter.Format.IsRightToLeft ^
(_lineIter.Format.Alignment == StringAlignment.Far)))
return _layout.getAdvance();
return _layout.getVisibleAdvance();
}
}
#endregion
#region Methods
internal void Draw(awt.Graphics2D g2d, float x, float y) {
if (_lineIter.Format.IsVertical)
_layout.draw (g2d, y + NativeY, -(x + NativeX));
else
_layout.draw(g2d, x + NativeX, y + NativeY );
}
internal awt.Shape GetOutline(float x, float y) {
geom.AffineTransform t = (geom.AffineTransform) _lineIter.Transform.clone();
if (_lineIter.Format.IsVertical)
t.translate(y + NativeY, -(x + NativeX));
else
t.translate(x + NativeX, y + NativeY);
return _layout.getOutline(t);
}
#endregion
}
}

View File

@@ -1,58 +0,0 @@
//
// System.Drawing.PrivateFontCollection.cs
//
// (C) 2005 Mainsoft Corporation (http://www.mainsoft.com)
// Author: Konstantin Triger (kostat@mainsoft.com)
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.IO;
using awt = java.awt;
using io = java.io;
using vmw.common;
namespace System.Drawing.Text
{
/// <summary>
/// Summary description for PrivateFontCollection.
/// </summary>
public sealed class PrivateFontCollection : FontCollection
{
public PrivateFontCollection()
{
}
public void AddFontFile(string filename) {
using(FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read)) {
io.InputStream stream = vmw.common.IOUtils.ToInputStream (fs);
awt.Font font = awt.Font.createFont(awt.Font.TRUETYPE_FONT, stream);
AddFont(font);
}
}
#if INTPTR_SUPPORT
public void AddMemoryFont(IntPtr memory, int length) {
}
#endif
}
}

View File

@@ -1,277 +0,0 @@
//
// System.Drawing.Test.TextLineIterator.jvm.cs
//
// Author:
// Konstantin Triger <kostat@mainsoft.com>
//
// Copyright (C) 2005 Mainsoft Corporation, (http://www.mainsoft.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Drawing.Drawing2D;
using font = java.awt.font;
using text = java.text;
using awt = java.awt;
using geom = java.awt.geom;
namespace System.Drawing.Text {
internal sealed class TextLineIterator {
#region Fields
readonly float _width;
readonly float _height;
readonly StringFormat _format;
readonly font.FontRenderContext _frc;
readonly string _s;
readonly Font _font;
readonly float _margin;
static readonly string NewLine;
static readonly geom.AffineTransform Rotate90Transform =
geom.AffineTransform.getRotateInstance(Math.PI/2);
font.TextMeasurer _measurer;
int _charsConsumed = 0;
int _currentPos = 0;
int _currentRun = 0;
float _accumulatedHeight = 0;
#endregion
#region ctors
static TextLineIterator() {
string newLine = Environment.NewLine;
if (newLine == null || newLine.Length == 0 || newLine[newLine.Length - 1] == '\n')
newLine = "\n";
NewLine = newLine;
}
internal TextLineIterator(string s, Font font, font.FontRenderContext frc, StringFormat format, float width, float height) {
_format = (format != null) ? format : new StringFormat();
_font = font;
_s = (s != null) ? s : String.Empty;
_frc = frc;
FontFamily ff = font.FontFamily;
_margin = font.Size*ff.GetDrawMargin(font.Style)/ff.GetEmHeight(font.Style);
_width = width;
_height = height;
}
#endregion
#region Properties
float WrapWidth
{
get {
float widthOrHeight = _format.IsVertical ? Height : Width;
if (!_format.IsGenericTypographic) {
widthOrHeight =
((_format.IsVertical ? Height : Width) - (0.463f * FontSize)) / 1.028f;
}
return widthOrHeight;
}
}
internal float WrapHeight {
get {
float widthOrHeight = _format.IsVertical ? Width : Height;
if (!_format.IsGenericTypographic) {
widthOrHeight = (_format.IsVertical ? Width : Height) / 1.08864f;
}
return widthOrHeight;
}
}
internal float Width {
get { return _width; }
}
internal float Height {
get { return _height; }
}
internal StringFormat Format {
get { return _format; }
}
internal float PadWidth (float origWidth)
{
if (Format.IsGenericTypographic)
return origWidth;
//This is a proximity to .NET calculated Width.
return origWidth * 1.028f + 0.463f * FontSize;
}
internal float PadHeight (float origHeight)
{
if (Format.IsGenericTypographic)
return origHeight;
//This is a proximity to .NET calculated Height.
return 1.08864f * origHeight;
}
internal float FontSize
{
get {
return _font.Size;
}
}
internal int CharsConsumed {
get { return _charsConsumed; }
}
internal int CurrentRun {
get { return _currentRun; }
}
internal int CurrentPosition {
get { return _currentPos; }
}
internal float AccumulatedHeight {
get { return _accumulatedHeight; }
}
internal float GetAdvanceBetween(int start, int limit) {
return _measurer.getAdvanceBetween(start, limit);
}
internal geom.AffineTransform Transform {
get { return Format.IsVertical ? Rotate90Transform : Matrix.IdentityTransform.NativeObject; }
}
#endregion
#region Methods
LineLayout NextTextLayoutFromMeasurer() {
if (_accumulatedHeight >= WrapHeight) {
_charsConsumed += _currentPos;
return null;
}
int limit = _measurer.getLineBreakIndex(_currentPos, WrapWidth);
int wordBreak = limit;
if (wordBreak < _currentRun) {
while (wordBreak >= _currentPos && char.IsLetterOrDigit(_s, _charsConsumed + wordBreak))
wordBreak--;
if (wordBreak > _currentPos)
limit = wordBreak + 1;
}
font.TextLayout layout = _measurer.getLayout(_currentPos, limit);
LineLayout lineLayout = new LineLayout(
layout,
this,
_accumulatedHeight);
float lineHeight = PadHeight (lineLayout.Ascent + lineLayout.Descent + lineLayout.Leading);
if (Format.LineLimit && (_accumulatedHeight + lineHeight > WrapHeight)) {
_charsConsumed += _currentPos;
return null;
}
_accumulatedHeight += lineHeight + lineLayout.Leading;
_currentPos = limit;
while (_currentPos < _currentRun) {
if (char.IsWhiteSpace(_s, _charsConsumed + _currentPos))
_currentPos++;
else
break;
}
return lineLayout;
}
internal LineLayout NextLine() {
if (_currentPos < _currentRun && !Format.NoWrap)
return NextTextLayoutFromMeasurer();
_charsConsumed += _currentRun;
if (_charsConsumed >= _s.Length)
return null;
string s;
int lineBreakIndex = _s.IndexOf(NewLine, _charsConsumed);
if (lineBreakIndex >= 0) {
s = _s.Substring(_charsConsumed, lineBreakIndex - _charsConsumed + NewLine.Length);
}
else
s = _s.Substring(_charsConsumed);
_currentRun = s.Length;
_currentPos = 0;
text.AttributedString aS = new text.AttributedString(s);
// TODO: add more attribs according to StringFormat
aS.addAttribute(font.TextAttribute.FONT, _font.NativeObject);
if((_font.Style & FontStyle.Underline) != FontStyle.Regular)
aS.addAttribute(font.TextAttribute.UNDERLINE, font.TextAttribute.UNDERLINE_ON);
if((_font.Style & FontStyle.Strikeout) != FontStyle.Regular)
aS.addAttribute(font.TextAttribute.STRIKETHROUGH, font.TextAttribute.STRIKETHROUGH_ON);
text.AttributedCharacterIterator charIter = aS.getIterator();
_measurer = new font.TextMeasurer(charIter, _frc);
return NextTextLayoutFromMeasurer();
}
internal geom.AffineTransform CalcLineAlignmentTransform() {
if (Format.LineAlignment == StringAlignment.Near)
return null;
float height = WrapHeight;
if (float.IsPositiveInfinity(height))
height = 0;
float shift = height - AccumulatedHeight;
if (height > 0 && shift <= 0)
return null;
if (Format.LineAlignment == StringAlignment.Center)
shift /= 2;
else
if (Format.IsVertical && Format.IsRightToLeft)
return null;
return Format.IsVertical ?
geom.AffineTransform.getTranslateInstance(shift, 0) :
geom.AffineTransform.getTranslateInstance(0, shift);
}
#endregion
}
}