Fixed logic to properly position XY Plots and Images
This commit is contained in:
parent
cdb7521b01
commit
e6c65b5139
@ -752,6 +752,7 @@ namespace VEPROMS.CSLA.Library
|
||||
int filecount = 1;
|
||||
while (selxy != null)
|
||||
{
|
||||
// B2017-007 Fixed logic to properly position an XY Plot
|
||||
string xyplot = selxy.Text;
|
||||
xyplot = xyplot.Replace("`", "\xB0");
|
||||
xyplot = xyplot.Replace("\xF8", "\xB0");
|
||||
@ -771,17 +772,8 @@ namespace VEPROMS.CSLA.Library
|
||||
// Setting the selected text to "" actually sets it to "\r", thus cnt-- (subtract one
|
||||
// from cnt since there's already a return in the string.
|
||||
cnt--;
|
||||
float x = adjustMargins ? (float)selxy.get_Information(LBWdInformation.wdHorizontalPositionRelativeToTextBoundary) :
|
||||
(float)selxy.get_Information(LBWdInformation.wdHorizontalPositionRelativeToPage);
|
||||
float y = adjustMargins ? (float)selxy.get_Information(LBWdInformation.wdVerticalPositionRelativeToTextBoundary) :
|
||||
(float)selxy.get_Information(LBWdInformation.wdVerticalPositionRelativeToPage);
|
||||
LBRange myRange = selxy.Paragraphs.First.Range;
|
||||
float yTop = adjustMargins ?(float)myRange.get_Information(LBWdInformation.wdVerticalPositionRelativeToTextBoundary) :
|
||||
(float)myRange.get_Information(LBWdInformation.wdVerticalPositionRelativeToPage);
|
||||
//float yTop1 = (float)myRange.get_Information(LBWdInformation.wdVerticalPositionRelativeToTextBoundary);
|
||||
|
||||
// some data had regular text embedded in the xyplot definition. If so, the plain text must
|
||||
// be left in the file. Otherwise, we can replace with empty text.
|
||||
PointF pt = GetLocation(selxy,adjustMargins);
|
||||
float y = pt.Y;
|
||||
string resXyPlot = xyplot;
|
||||
string txt = FindEmbeddedText(selxy.Text, ref resXyPlot);
|
||||
if (txt != null)
|
||||
@ -796,17 +788,30 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
|
||||
pngFile = VlnSettings.TemporaryFolder + @"\XYPlot" + filecount.ToString() + @".png"; //@"C:\Temp\XYPlot1.png";
|
||||
//FileInfo fi = new FileInfo(pngFile);
|
||||
//_MyLog.WarnFormat("PNG Name = {0}, size = {1}", fi.Name, fi.Length);
|
||||
filecount++;
|
||||
RectangleF plotRect = CreatePlot(pngFile, xyplot, 600F, FormForPlotGraphics);
|
||||
|
||||
float xAdjust = 0; //(float)-sect.MyDocStyle.Layout.LeftMargin;
|
||||
RectangleF plotRect = CreatePlot(pngFile, xyplot, 600F, FormForPlotGraphics);
|
||||
float yAdjust = selxy.Font.Size;
|
||||
LBShape shape = myDoc.Shapes.AddPicture(pngFile, x + xAdjust + plotRect.X, yAdjust + y - yTop + plotRect.Y, selxy.Range);
|
||||
float xxx = pt.X + plotRect.X;
|
||||
if (xxx < 0 && xxx > -.5)
|
||||
xxx = 0;
|
||||
float yyy = yAdjust + y + plotRect.Y;
|
||||
LBShape shape = myDoc.Shapes.AddPicture(pngFile, xxx, yyy, selxy.Range);
|
||||
File.Delete(pngFile);
|
||||
if (adjustMargins)
|
||||
{
|
||||
shape.RelativeVerticalPosition = LBWdRelativeVerticalPosition.wdRelativeVerticalPositionMargin;
|
||||
shape.RelativeHorizontalPosition = LBWdRelativeHorizontalPosition.wdRelativeHorizontalPositionMargin;// .wdRelativeHorizontalPositionMargin;
|
||||
}
|
||||
else
|
||||
{
|
||||
shape.RelativeVerticalPosition = LBWdRelativeVerticalPosition.wdRelativeVerticalPositionPage;
|
||||
shape.RelativeHorizontalPosition = LBWdRelativeHorizontalPosition.wdRelativeHorizontalPositionPage;// .wdRelativeHorizontalPositionMargin;
|
||||
}
|
||||
shape.LockAspectRatio = LBMsoTriState.msoTrue;
|
||||
shape.Width = plotRect.Width;
|
||||
shape.Left = xxx;
|
||||
shape.Top = pt.Y;
|
||||
selxy.WholeStory();
|
||||
selxy = FindXyPlot();
|
||||
}
|
||||
@ -865,14 +870,14 @@ namespace VEPROMS.CSLA.Library
|
||||
float width = 72 * Int32.Parse(vals[3], System.Globalization.NumberStyles.AllowHexSpecifier) / 12.0F;
|
||||
int lines = Int32.Parse(vals[2], System.Globalization.NumberStyles.AllowHexSpecifier);
|
||||
float height = 72 * lines / 6.0F;
|
||||
float x = adjustMargins ? (float)sel.get_Information(LBWdInformation.wdHorizontalPositionRelativeToTextBoundary):
|
||||
(float)sel.get_Information(LBWdInformation.wdHorizontalPositionRelativeToPage);
|
||||
// 9.25 is the approximate offset of the base line of the font, i.e. doesn't include descender.
|
||||
float locvertpage = adjustMargins ? (float)sel.get_Information(LBWdInformation.wdVerticalPositionRelativeToTextBoundary) :
|
||||
(float)sel.get_Information(LBWdInformation.wdVerticalPositionRelativeToPage);
|
||||
float y = locvertpage + ((sel.Font.Size * 9.25F) / 12);
|
||||
PointF pt = GetLocation(sel, adjustMargins);
|
||||
float xxx = pt.X;
|
||||
if (xxx < 0 && xxx > -.5)
|
||||
xxx = 0;
|
||||
float yyy = pt.Y;
|
||||
sel.Text = "";
|
||||
LBShape shape = myDoc.Shapes.AddPicture(roImageFile.MyFile.FullName, x, y, sel.Range);
|
||||
LBShape shape = myDoc.Shapes.AddPicture(roImageFile.MyFile.FullName, xxx, yyy, sel.Range);
|
||||
File.Delete(pngFile);
|
||||
if (adjustMargins)
|
||||
{
|
||||
shape.RelativeVerticalPosition = LBWdRelativeVerticalPosition.wdRelativeVerticalPositionMargin;
|
||||
@ -883,10 +888,11 @@ namespace VEPROMS.CSLA.Library
|
||||
shape.RelativeVerticalPosition = LBWdRelativeVerticalPosition.wdRelativeVerticalPositionPage;
|
||||
shape.RelativeHorizontalPosition = LBWdRelativeHorizontalPosition.wdRelativeHorizontalPositionPage;// .wdRelativeHorizontalPositionMargin;
|
||||
}
|
||||
shape.Top = y; // Reset value after setting flag RelativeVerticalPosition
|
||||
shape.Left = x;
|
||||
shape.LockAspectRatio = LBMsoTriState.msoTrue;
|
||||
shape.Width = width;
|
||||
shape.Height = height;
|
||||
shape.Left = xxx;
|
||||
shape.Top = pt.Y;
|
||||
imageROTokenReplaced = true;
|
||||
}
|
||||
if (!imageROTokenReplaced)
|
||||
@ -894,6 +900,7 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
else if ((int)type == 4) // X-Y Plot
|
||||
{
|
||||
// B2017-007 Fixed logic to properly position an XY Plot
|
||||
try
|
||||
{
|
||||
val = val.Replace("`", "\xB0");
|
||||
@ -905,40 +912,23 @@ namespace VEPROMS.CSLA.Library
|
||||
int pstart = val.IndexOf("<<G"); // find the starting Plot Command
|
||||
AddPrecedingText(sel, val.Substring(0, pstart),0.0F);// replace the RO token with what's in front of the X/Y Plot
|
||||
val = val.Substring(pstart); // set val to the start of the plot commands
|
||||
//float width = 72 * Int32.Parse(vals[3], System.Globalization.NumberStyles.AllowHexSpecifier) / 12.0F;
|
||||
//float height = 72 * lines / 6.0F;
|
||||
pngFile = VlnSettings.TemporaryFolder + @"\XYPlot1.png"; //@"C:\Temp\XYPlot1.png";
|
||||
RectangleF plotRect = CreatePlot(pngFile, val, 600F, FormForPlotGraphics);
|
||||
//FileInfo fi = new FileInfo(pngFile);
|
||||
//_MyLog.WarnFormat("PNG Name = {0}, size = {1}", fi.Name, fi.Length);
|
||||
|
||||
//LBShape shape = myDoc.Shapes.AddPicture(@"C:\Temp\XYPlot.png", 0, 0, sel.Range);
|
||||
float x = adjustMargins ? (float)sel.get_Information(LBWdInformation.wdHorizontalPositionRelativeToTextBoundary) :
|
||||
(float)sel.get_Information(LBWdInformation.wdHorizontalPositionRelativeToPage);
|
||||
float y = adjustMargins ? (float)sel.get_Information(LBWdInformation.wdVerticalPositionRelativeToTextBoundary):
|
||||
(float)sel.get_Information(LBWdInformation.wdVerticalPositionRelativeToPage);
|
||||
// if there is regular text before the plot, then count the number of lines
|
||||
// and adjust the y position accordingly
|
||||
PointF pt = GetLocation(sel,adjustMargins);
|
||||
float xxx = pt.X + plotRect.X;
|
||||
if (xxx < 0 && xxx > -.5)
|
||||
xxx = 0;
|
||||
float y = pt.Y;
|
||||
int idx = sel.Text.IndexOf("\r");
|
||||
while ((idx > 0) && (idx < sel.Text.Length + 1))
|
||||
{
|
||||
idx = sel.Text.IndexOf("\r", idx + 1);
|
||||
y += (float)sel.ParagraphFormat.LineSpacing; // get_Information(LBWdLineSpacing.wdLineSpaceSingle);
|
||||
}
|
||||
//LBInlineShape shape = sel.InlineShapes.AddPicture(pngFile);
|
||||
LBRange myRange = sel.Paragraphs.First.Range;
|
||||
float yTop = adjustMargins ? (float)myRange.get_Information(LBWdInformation.wdVerticalPositionRelativeToTextBoundary) :
|
||||
(float)myRange.get_Information(LBWdInformation.wdVerticalPositionRelativeToPage);
|
||||
float xAdjust = 0;// = (float)-sect.MyDocStyle.Layout.LeftMargin;
|
||||
float yAdjust = sel.Font.Size;
|
||||
// The following two lines made the xyplot location for WCN2 match the 16bit output. However, how the
|
||||
// xTweak value is determined is phantom of Rich's mind. Word document location of the RO token
|
||||
// will be modified in data before delivery so that this xTweak is not needed.
|
||||
//float xTweak = -(30 + xAdjust) / 3; // Used to align plots for WCN2.
|
||||
//LBShape shape = myDoc.Shapes.AddPicture(pngFile, x + xAdjust + plotRect.X + xTweak, yAdjust + y - yTop + plotRect.Y, sel.Range);
|
||||
LBShape shape = myDoc.Shapes.AddPicture(pngFile, x + xAdjust + plotRect.X, yAdjust + y - yTop + plotRect.Y, sel.Range);
|
||||
float yyy = yAdjust + y + plotRect.Y;
|
||||
LBShape shape = myDoc.Shapes.AddPicture(pngFile, xxx, yyy, sel.Range);
|
||||
File.Delete(pngFile);
|
||||
//shape.RelativeHorizontalPosition = LBWdRelativeHorizontalPosition.wdRelativeHorizontalPositionPage;// .wdRelativeHorizontalPositionMargin;
|
||||
if (adjustMargins)
|
||||
{
|
||||
shape.RelativeVerticalPosition = LBWdRelativeVerticalPosition.wdRelativeVerticalPositionMargin;
|
||||
@ -949,20 +939,11 @@ namespace VEPROMS.CSLA.Library
|
||||
shape.RelativeVerticalPosition = LBWdRelativeVerticalPosition.wdRelativeVerticalPositionPage;
|
||||
shape.RelativeHorizontalPosition = LBWdRelativeHorizontalPosition.wdRelativeHorizontalPositionPage;// .wdRelativeHorizontalPositionMargin;
|
||||
}
|
||||
shape.Left = x + xAdjust + plotRect.X;
|
||||
//shape.Top = yAdjust + y - yTop + plotRect.Y;
|
||||
shape.Top = yAdjust + y + plotRect.Y;
|
||||
shape.LockAspectRatio = LBMsoTriState.msoTrue;
|
||||
//shape.Width = .89F * shape.Width;
|
||||
//shape.Width = float.Parse(tbAdjust.Text) * shape.Width;
|
||||
shape.Width = plotRect.Width;
|
||||
//shape.Height = .89F * shape.Height;
|
||||
shape.Left = xxx;
|
||||
shape.Top = pt.Y;
|
||||
sel.WholeStory();
|
||||
// TODO: Do we want to color code ROs
|
||||
//sel.Range.Font.Color = LBWdColor.wdColorRed;
|
||||
//shape.Width = width;
|
||||
//shape.Height = height;
|
||||
//imageROTokenReplaced = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -1013,6 +994,18 @@ namespace VEPROMS.CSLA.Library
|
||||
return fileName;
|
||||
}
|
||||
}
|
||||
private static PointF GetLocation(LBSelection sel, bool adjustMargins)
|
||||
{
|
||||
LBRange rng0 = MyApp.ActiveDocument.Range(0, 0);
|
||||
LBRange rng1 = MyApp.ActiveDocument.Range(sel.Start, sel.Start);
|
||||
float fx0 = adjustMargins ? (float)rng0.get_Information(LBWdInformation.wdHorizontalPositionRelativeToPage) : 0;
|
||||
float fy0 = adjustMargins ? (float)rng0.get_Information(LBWdInformation.wdVerticalPositionRelativeToPage) : 0;
|
||||
float fx1 = (float)rng1.get_Information(LBWdInformation.wdHorizontalPositionRelativeToPage);
|
||||
float fy1 = (float)rng1.get_Information(LBWdInformation.wdVerticalPositionRelativeToPage);
|
||||
//_MyLog.WarnFormat("X {0}-{1}={2}",fx1, fx0, fx1-fx0);
|
||||
//_MyLog.WarnFormat("Y {0}-{1}={2}",fy1, fy0, fy1-fy0);
|
||||
return new PointF(fx1-fx0,fy1-fy0);
|
||||
}
|
||||
// Reads the Word file containing the resolved ROs
|
||||
// used when adding to DocReplace
|
||||
private static byte[] GetBytes(string filename)
|
||||
|
Loading…
x
Reference in New Issue
Block a user