/// <summary> /// Calculates the caption path in the untransformed state. /// </summary> /// <param name="layoutX">X coordinate of the layout rectangle</param> /// <param name="layoutY">Y coordinate of the layout rectangle</param> /// <param name="layoutW">Width of the layout rectangle</param> /// <param name="layoutH">Height of the layout rectangle</param> /// <param name="characterStyle">Character style of the caption</param> /// <param name="paragraphStyle">Paragraph style of the caption</param> /// <returns></returns> public bool CalculatePath(int layoutX, int layoutY, int layoutW, int layoutH, ICharacterStyle characterStyle, IParagraphStyle paragraphStyle) { if (characterStyle == null) throw new ArgumentNullException("charStyle"); if (paragraphStyle == null) throw new ArgumentNullException("paragraphStyle"); if (string.IsNullOrEmpty(captionText)) return true; else if (textPath != null /*&& layoutW > 0 && layoutH > 0*/) { // Collect objects for calculating text layout Font font = ToolCache.GetFont(characterStyle); StringFormat formatter = ToolCache.GetStringFormat(paragraphStyle); Rectangle textBounds = Rectangle.Empty; textBounds.X = layoutX + paragraphStyle.Padding.Left; textBounds.Y = layoutY + paragraphStyle.Padding.Top; textBounds.Width = Math.Max(1, layoutW - paragraphStyle.Padding.Horizontal); textBounds.Height = Math.Max(1, layoutH - paragraphStyle.Padding.Vertical); // Create text path textPath.Reset(); textPath.StartFigure(); textPath.AddString(PathText, font.FontFamily, (int)font.Style, characterStyle.Size, textBounds, formatter); textPath.CloseFigure(); #if DEBUG_DIAGNOSTICS if (textPath.PointCount == 0 && PathText.Trim() != string.Empty) { Size textSize = TextMeasurer.MeasureText(PathText, font, textBounds.Size, paragraphStyle); Debug.Print("Failed to create TextPath - please check if the caption bounds are too small for the text."); } #endif return true; } return false; }
/// <summary> /// 重构文件或目录的名字, /// 并返回重构后的新完整路径 /// </summary> /// <param name="path">待重构的路径</param> /// <param name="newSimple">文件或目录重构后的新名称, /// 不带扩展名,如果为<see langword="null"/>,代表不更改</param> /// <param name="newExtension">文件重构后的新扩展名,不带点号, /// 如果为<see langword="null"/>,代表该路径不是文件,或不更改扩展名</param> /// <returns></returns> public static string RefactoringPath(PathText path, string?newSimple, string?newExtension) { var(simple, extended) = SplitPathFile(path); var father = Path.GetDirectoryName(path) !; return(Path.Combine(father, GetFullName(newSimple ?? simple, newExtension ?? extended))); }
public bool Validate() { if (ExtensionText != null && NameText != null && !NameText.EndsWith(ExtensionText)) { return(false); } if (NameText != null && PathText != null && !PathText.EndsWith(NameText)) { return(false); } if (PathText != null) { FsNode parent = Parent; // Stop before the root node while (parent?.Parent != null) { if (!PathText.StartsWith(parent.PathText)) { return(false); } parent = parent.Parent; } } return(true); }
/// <summary> /// 通过路径从缓存字典中提取Office文件, /// 不会引发文件被占用的异常 /// </summary> /// <typeparam name="Obj">返回值类型</typeparam> /// <param name="path">Office文件的路径</param> /// <param name="delegate">如果该Office文件未被创建, /// 则通过这个委托创建文件并返回,它的参数就是文件路径</param> /// <returns>提取到的Office文件</returns> private protected static Obj GetOfficeFile <Obj>(PathText path, Func <PathText, Obj> @delegate) where Obj : OfficeFile { if (PathCache.TryGetValue(path, out var file)) { if (file.Target != null) { return(file.Target.To <Obj>()); } PathCache.Remove(path); } return(@delegate(path)); }
private void ConvertFile(object sender, EventArgs e) { try { _getWordPlainText = new GetWordPlainText(PathText.Text); PathText.Clear(); LoadResult = _getWordPlainText.ReadWordDocument(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error"); LoadResult = string.Empty; } finally { _getWordPlainText?.Dispose(); } }
protected override Text CreateAdvancedText(string text, Graphics graphics) { if (TextPath == null || TextPath.IsEmpty) { throw new InvalidOperationException("Path for CurvedText cannot be empty"); } if (PathStart > PathEnd || Utils.EqualsOfFloatNumbers(PathStart, PathEnd)) { throw new InvalidOperationException("Start point of path must be less than end point"); } var dpi = graphics.DpiX; FitTextToPath(dpi); var font = CreateFont(graphics); var path = GetDrawingTextPath(dpi); var pathText = new PathText(text, font) { // CurveText doesn't support underline Alignment = VOAligmnentToAdvanced(Alignment), Stretch = Stretch, Tracking = Tracking, Leading = Utils.EqualsOfFloatNumbers(0, Leading) ? font.Size * 1.2f : Leading, AutoExtend = true }; if (!Utils.EqualsOfFloatNumbers(1, HorizontalScale) || !Utils.EqualsOfFloatNumbers(1, VerticalScale)) { path.Scale(1 / HorizontalScale, 1 / VerticalScale); pathText.Transform.Scale(HorizontalScale, VerticalScale); } pathText.Path = path.ToAdvancedPath(); pathText.Start = PathStart; pathText.End = PathEnd; return(pathText); }
/// <summary> /// 如果一个路径是文件,返回文件对象, /// 是目录,返回目录对象, /// 不存在,返回<see langword="null"/> /// </summary> /// <param name="path">要检查的路径</param> /// <returns></returns> public static IIO?IO(PathText path) => ToolPath.GetPathState(path) switch {
/// <summary> /// 用指定的路径初始化目录对象 /// </summary> /// <param name="path">指定的路径</param> /// <param name="checkExist">在路径不存在的时候,如果这个值为<see langword="true"/>,会抛出一个异常, /// 如果为<see langword="false"/>,则不会抛出异常,而是会创建这个目录</param> public static IDirectory Directory(PathText path, bool checkExist = true) => new DirectoryRealize(path, checkExist);
/// <summary> /// 用指定的路径初始化文件对象, /// 不允许指定不存在的路径 /// </summary> /// <param name="path">指定的路径</param> /// <param name="checkExist">在文件不存在的时候,如果这个值为<see langword="true"/>, /// 则抛出一个异常,为<see langword="false"/>,则不会抛出异常,而是会创建一个新文件</param> public static IFile File(PathText path, bool checkExist = true) => new FileRealize(path, checkExist);
/// <summary> /// 将文件读取到内存,并返回读取到的图片 /// </summary> /// <param name="Path">图片所在的文件</param> /// <returns></returns> public static async Task <IImage> ImageMemory(PathText Path) { var stream = CreateIO.File(Path).GetBitPipe(); return(ImageMemory(await stream.Read().FirstAsync(), ToolPath.SplitPathFile(Path).Extended)); }
private static void MergeLayers(PsdReader psdReader, Graphics graphics, Func <PsdTextFrame, string> getLayerText) { for (int i = 0; i < psdReader.Frames.Count; i++) { var frame = psdReader.Frames[i]; if (frame.Type == FrameType.Text) { var textFrame = (PsdTextFrame)frame; var layerText = getLayerText(textFrame); Text text; var font = graphics.CreateFont(textFrame.FontName, textFrame.FontSize); if (textFrame.Path != null) { text = new PathText(textFrame.Text, font) { Path = textFrame.Raw.Path }; } else if (textFrame.TextBox.Width == 0 || textFrame.TextBox.Height == 0) { text = new PlainText(layerText, font) { Position = new System.Drawing.PointF(textFrame.Raw.TextBox.Left, textFrame.Raw.TextBox.Top) }; } else { text = new BoundedText(layerText, font) { Rectangle = textFrame.Raw.TextBox }; } text.Alignment = JustificationToTextAlignment(textFrame.Justification); text.Brush = new SolidBrush(textFrame.Color); text.Tracking = textFrame.Tracking; text.Transform = textFrame.Transform; graphics.DrawText(text); } else if (frame.Type == FrameType.Raster) { using (var frameBitmap = frame.GetBitmap()) { graphics.DrawImage(frameBitmap, frame.X, frame.Y); } } else if (frame.Type == FrameType.Shape) { var shapeFrame = (PsdShapeFrame)frame; var path = shapeFrame.VectorMask; graphics.FillPath(shapeFrame.Brush, path); } } }
public Task PrintFromPageToFile(Range?Page, PathText FilePath) => PrintBase(Page, FilePath: FilePath);