简体   繁体   English

设置removeChild后,run原来的字体变了

[英]Aspose after removeChild, the run original font is changed

I have a paragraph para1 and a run, before remove the run, I first keep the run font by我有一个段落 para1 和一个运行,在删除运行之前,我首先保留运行字体

Font originFont = run1.getFont();

and I check debug mode, the originFont.getName() return Times New Roman.我检查调试模式,originFont.getName() 返回 Times New Roman。 but then I remove the run by但后来我删除了运行

para1.removeChild(run1);

then I check the originFont.getName(), it change to Calibri, why?然后我检查了originFont.getName(),它变成了Calibri,为什么?

在此处输入图片说明

在此处输入图片说明

Font of the run is not specified directly in run only.仅在运行中不直接指定运行的字体。 This is complex value that is inherited from the run's parent, document styles, themes and document defaults.这是从运行的父级、文档样式、主题和文档默认值继承的复杂值。 When you remove run from the document it's parent is set to null and the code that gets font name cannot get the inherited values and returns value that is directly specified in the run or if it is not directly specified returns default value.当您从文档中删除 run 时,它的父项设置为 null,并且获取字体名称的代码无法获取继承值并返回在运行中直接指定的值,或者如果未直接指定则返回默认值。

Let's consider the following three paragraphs.让我们考虑以下三段。 The first is simple bold text with Normal style that uses Calibri font.第一个是使用 Calibri 字体的普通样式的简单粗体文本。 The second is paragraph with the same normal style, but with directly specified font for run and paragraph.第二个是具有相同普通样式的段落,但直接指定了运行和段落的字体。 The third is paragraph with a custom ArialStyle style, that has Arial style specified.第三个是具有自定义 ArialStyle 样式的段落,该样式指定了 Arial 样式。

    <w:p w14:paraId="2787B8CC" w14:textId="607BD13B" w:rsidR="00C96F00" w:rsidRPr="00CA1A63" w:rsidRDefault="00CA1A63">
  <w:pPr>
    <w:rPr>
      <w:b />
      <w:bCs />
    </w:rPr>
  </w:pPr>
  <w:r w:rsidRPr="00CA1A63">
    <w:rPr>
      <w:b />
      <w:bCs />
    </w:rPr>
    <w:t>Bold Calibri</w:t>
  </w:r>
</w:p>
<w:p w14:paraId="7F64B104" w14:textId="7CCF8DB9" w:rsidR="00CA1A63" w:rsidRPr="00C75FFA" w:rsidRDefault="00CA1A63">
  <w:pPr>
    <w:rPr>
      <w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman" w:cs="Times New Roman" />
      <w:i />
      <w:iCs />
    </w:rPr>
  </w:pPr>
  <w:r w:rsidRPr="00C75FFA">
    <w:rPr>
      <w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman" w:cs="Times New Roman" />
      <w:i />
      <w:iCs />
    </w:rPr>
    <w:t>Italic Times New Roman</w:t>
  </w:r>
</w:p>
<w:p w14:paraId="0D91CAFA" w14:textId="21A94755" w:rsidR="00CA1A63" w:rsidRDefault="00CA1A63" w:rsidP="007A778A">
  <w:pPr>
    <w:pStyle w:val="ArialStyle" />
  </w:pPr>
  <w:r>
    <w:t xml:space="preserve">Normal arial style</w:t>
  </w:r>
</w:p>

If you remove the run from the first paragraph its font will not be changed because document default is Calibri.如果您从第一段中删除 run,它的字体不会更改,因为文档默认为 Calibri。

If you remove the run from the second paragraph the font will not be changed because font name is directly specified.如果您从第二段中删除 run,则字体不会更改,因为直接指定了字体名称。

If you remove the run from the third paragraph the font will be changed to Calibri – document default.如果您从第三段中删除运行,字体将更改为 Calibri – 文档默认值。 Because when you remove a run it's parent is null and code does not have access to the parent paragraph's style.因为当您删除运行时,它的父级为空,并且代码无权访问父级段落的样式。

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

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