简体   繁体   English

如何用firemonkey更改字体JPant?

[英]How change font JPaint with firemonkey?

I need to print a PDF file using firemonkey with JPdfDocument ; 我需要使用firemonkeyJPdfDocument打印PDF文件;

I've written the code below its work, but don't change the font: Here is the documentation link 我已经在其工作下面编写了代码,但不要更改字体: 这是文档链接

procedure TForm1.btGerarPDFClick(Sender: TObject);
var
   Document: JPdfDocument;
   PageInfo: JPdfDocument_PageInfo;
   Page: JPdfDocument_Page;
   Canvas: JCanvas;
   Paint: JPaint;
   Recto: JRect;
   Rect: JRect;
   FileName: string;
   OutputStream: JFileOutputStream;
   Intent: JIntent;

   begin
       // create Pdf document
       Document := TJPdfDocument.JavaClass.init;
       try
            // create page  1
            PageInfo := TJPageInfo_Builder.JavaClass.init(100, 100, 1).create;
            Page := Document.startPage(PageInfo);

            Canvas := Page.getCanvas;
            Paint := TJPaint.JavaClass.init;

            Paint.setARGB($FF, 0, 0, $FF);

           // I need to change the font to: Courier New, Size 9

           Canvas.drawText(StringToJString('Courier New 9'), 10, 50, Paint);

          // I need to change the font to: Courier New, Size 14

          Canvas.drawText(StringToJString('Courier 14'), 10, 50, Paint);

         Document.finishPage(Page);

        // write PDF document to file
        FileName := TPath.Combine(TPath.GetSharedDocumentsPath, 'demo.pdf');
          OutputStream := TJFileOutputStream.JavaClass.init
         (StringToJString(FileName));
           try
             Document.writeTo(OutputStream);
           finally
             OutputStream.close;
        end;
   finally
      Document.close;
   end;

   // start PDF viewer
      Intent := TJIntent.JavaClass.init;
      Intent.setAction(TJIntent.JavaClass.ACTION_VIEW);
      Intent.setDataAndType(FileNameToUri(FileName),
      StringToJString('application/pdf'));
      Intent.setFlags(TJIntent.JavaClass.FLAG_ACTIVITY_NO_HISTORY or
      TJIntent.JavaClass.FLAG_ACTIVITY_CLEAR_TOP);
      SharedActivity.StartActivity(Intent);
   end;
Paint.setARGB($FF, 0, 0, 0); // color
paint.setFakeBoldText(true);// font bol
Paint.setTextSize(16); // font size
Paint.setFontFeatureSettings(StringToJString('Segoe Script')); //font name

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM