1 /*
2 * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
479 protected void checkControlWord(MutableAttributeSet currentAttributes,
480 AttributeSet newAttributes,
481 RTFAttribute word)
482 throws IOException
483 {
484 Object parm;
485
486 if ((parm = attrDiff(currentAttributes, newAttributes,
487 word.swingName(), MagicToken)) != null) {
488 if (parm == MagicToken)
489 parm = null;
490 if (!word.writeValue(parm, this, true) &&
491 word instanceof RTFAttributes.AssertiveAttribute ) {
492 currentAttributes.removeAttribute(word.swingName());
493 }
494 }
495 }
496
497 protected void checkControlWords(MutableAttributeSet currentAttributes,
498 AttributeSet newAttributes,
499 RTFAttribute words[],
500 int domain)
501 throws IOException
502 {
503 int wordIndex;
504 int wordCount = words.length;
505 for(wordIndex = 0; wordIndex < wordCount; wordIndex++) {
506 RTFAttribute attr = words[wordIndex];
507 if (attr.domain() == domain)
508 checkControlWord(currentAttributes, newAttributes, attr);
509 }
510 }
511
512 void updateSectionAttributes(MutableAttributeSet current,
513 AttributeSet newAttributes,
514 boolean emitStyleChanges)
515 throws IOException
516 {
517 if (emitStyleChanges) {
518 Object oldStyle = current.getAttribute("sectionStyle");
519 Object newStyle = findStyleNumber(newAttributes, Constants.STSection);
579
580 Object oldTabs = current.getAttribute(Constants.Tabs);
581 Object newTabs = newAttributes.getAttribute(Constants.Tabs);
582 if (oldTabs != newTabs) {
583 if (oldTabs != null) {
584 resetParagraphAttributes(current);
585 oldTabs = null;
586 oldStyle = null;
587 }
588 }
589
590 if (oldStyle != newStyle && newStyle != null) {
591 writeControlWord("s", ((Integer)newStyle).intValue());
592 current.addAttribute("paragraphStyle", newStyle);
593 }
594
595 checkControlWords(current, newAttributes,
596 RTFAttributes.attributes, RTFAttribute.D_PARAGRAPH);
597
598 if (oldTabs != newTabs && newTabs != null) {
599 TabStop tabs[] = (TabStop[])newTabs;
600 int index;
601 for(index = 0; index < tabs.length; index ++) {
602 TabStop tab = tabs[index];
603 switch (tab.getAlignment()) {
604 case TabStop.ALIGN_LEFT:
605 case TabStop.ALIGN_BAR:
606 break;
607 case TabStop.ALIGN_RIGHT:
608 writeControlWord("tqr");
609 break;
610 case TabStop.ALIGN_CENTER:
611 writeControlWord("tqc");
612 break;
613 case TabStop.ALIGN_DECIMAL:
614 writeControlWord("tqdec");
615 break;
616 }
617 switch (tab.getLeader()) {
618 case TabStop.LEAD_NONE:
619 break;
|
1 /*
2 * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
479 protected void checkControlWord(MutableAttributeSet currentAttributes,
480 AttributeSet newAttributes,
481 RTFAttribute word)
482 throws IOException
483 {
484 Object parm;
485
486 if ((parm = attrDiff(currentAttributes, newAttributes,
487 word.swingName(), MagicToken)) != null) {
488 if (parm == MagicToken)
489 parm = null;
490 if (!word.writeValue(parm, this, true) &&
491 word instanceof RTFAttributes.AssertiveAttribute ) {
492 currentAttributes.removeAttribute(word.swingName());
493 }
494 }
495 }
496
497 protected void checkControlWords(MutableAttributeSet currentAttributes,
498 AttributeSet newAttributes,
499 RTFAttribute[] words,
500 int domain)
501 throws IOException
502 {
503 int wordIndex;
504 int wordCount = words.length;
505 for(wordIndex = 0; wordIndex < wordCount; wordIndex++) {
506 RTFAttribute attr = words[wordIndex];
507 if (attr.domain() == domain)
508 checkControlWord(currentAttributes, newAttributes, attr);
509 }
510 }
511
512 void updateSectionAttributes(MutableAttributeSet current,
513 AttributeSet newAttributes,
514 boolean emitStyleChanges)
515 throws IOException
516 {
517 if (emitStyleChanges) {
518 Object oldStyle = current.getAttribute("sectionStyle");
519 Object newStyle = findStyleNumber(newAttributes, Constants.STSection);
579
580 Object oldTabs = current.getAttribute(Constants.Tabs);
581 Object newTabs = newAttributes.getAttribute(Constants.Tabs);
582 if (oldTabs != newTabs) {
583 if (oldTabs != null) {
584 resetParagraphAttributes(current);
585 oldTabs = null;
586 oldStyle = null;
587 }
588 }
589
590 if (oldStyle != newStyle && newStyle != null) {
591 writeControlWord("s", ((Integer)newStyle).intValue());
592 current.addAttribute("paragraphStyle", newStyle);
593 }
594
595 checkControlWords(current, newAttributes,
596 RTFAttributes.attributes, RTFAttribute.D_PARAGRAPH);
597
598 if (oldTabs != newTabs && newTabs != null) {
599 TabStop[] tabs = (TabStop[])newTabs;
600 int index;
601 for(index = 0; index < tabs.length; index ++) {
602 TabStop tab = tabs[index];
603 switch (tab.getAlignment()) {
604 case TabStop.ALIGN_LEFT:
605 case TabStop.ALIGN_BAR:
606 break;
607 case TabStop.ALIGN_RIGHT:
608 writeControlWord("tqr");
609 break;
610 case TabStop.ALIGN_CENTER:
611 writeControlWord("tqc");
612 break;
613 case TabStop.ALIGN_DECIMAL:
614 writeControlWord("tqdec");
615 break;
616 }
617 switch (tab.getLeader()) {
618 case TabStop.LEAD_NONE:
619 break;
|