Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: .NET/Link and two-dimensional strings

  • To: mathgroup at smc.vnet.net
  • Subject: [mg67262] Re: .NET/Link and two-dimensional strings
  • From: "colin" <colin.ladyka at scf.sk.ca>
  • Date: Wed, 14 Jun 2006 06:30:07 -0400 (EDT)
  • References: <e63msq$kqp$1@smc.vnet.net><e6b6h4$dha$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

David Bailey wrote:
> colin wrote:
> > The following two lines export a jpeg file containing RED text when
> > executed in a notebook:
> >
> > myText="\!\(\*StyleBox[\"my text\",\nFontColor->RGBColor[1, 0, 0]]\)";
> > Export["C:\\Temp\\myText.jpg",Show[Graphics[Text[myText,{0,0}]]]];
> >
> > If I put these same lines in a file called myText.txt, and then read
> > this file with the following .NET code, the kernel produces a jpeg file
> > containing BLACK text.
> >
> > using System;
> > using System.IO;
> > using Wolfram.NETLink;
> >
> > namespace WriTest
> > {
> >     static class Program
> >     {
> >          static void Main()
> >         {
> >             MathKernel mathKernel = new MathKernel();
> >
> >             StreamReader streamReader = new
> > StreamReader(@"C:\Temp\myFile.txt");
> >             string command1 = streamReader.ReadLine();
> >             string command2 = streamReader.ReadLine();
> >             streamReader.Close();
> >
> >             mathKernel.Compute(command1);
> >             string result1 = mathKernel.Result.ToString();
> >
> >             mathKernel.Compute(command2);
> >             string result2 = mathKernel.Result.ToString();
> >        }
> >     }
> > }
> >
> > Note an examination of command1 within the debugger, just before it is
> > sent to the kernel, produces the following string:
> >
> > "myText=\"\\!\\(\\*StyleBox[\\\"my text\\\",\\nFontColor->RGBColor[1,
> > 0, 0]]\\)\";"
> >
> > Wrapping ToExpression around this string in a Mathematica notebook
> > results in the desired red text. This problem seems to be related to
> > the need for the StyleBox which can only be found in a two-dimensional
> > string.  Other two dimensional string also lead to problems.
> >
> > What is my problem?
> >
> >
> >     Colin
> >
> I am much more familiar with J/Link rather than .NET/Link, but the point
> is that you can't expect strings containing 2-D expressions and/or
> font/style changes to work in .NET. I suggest you use Export to convert
> your string (or the expression that it represents) into a GIF file, and
> then pass that to .NET/Link and use it as an image.
>
> David Bailey
> http://www.dbaileyconsultancy.co.uk

This is exactly the problem. We create the String, Use
Graphics[Text[...]] to create a graphics, then export this to a jpeg.
The jpeg has black text, not red. We traced back and found that the
colour change occurs immediately on running ToExpression in the
creation of the string, so changing to gif can not help. We agree that
2D strings of all types seem not work in .NET, but do not understand
why.... It is as if the way the kernel behaves when called via .NET is
different than when it is called from the Notebook front end. Is there
some initialization/flag required to make this work?

You state that "...you can't expect strings containing 2-D expressions
... to work in .NET." Why do you say this? Is this behaviour and it's
cause documented somewhere? 

Colin


  • Prev by Date: Re: Resolve/Reduce is taking forever
  • Next by Date: Getting the (correct) roots of a polynomial
  • Previous by thread: Re: .NET/Link and two-dimensional strings
  • Next by thread: Re: .NET/Link and two-dimensional strings