123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- /*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
- /* $Id$ */
-
- package org.apache.fop.traits;
-
- import java.io.ObjectStreamException;
-
- import org.apache.fop.fo.Constants;
-
- /** Enumeration class for writing mode trait. */
- public final class WritingMode extends TraitEnum {
-
- private static final long serialVersionUID = 1L;
-
- private static final String[] WRITING_MODE_NAMES = new String[]
- {"lr-tb", "rl-tb", "tb-lr", "tb-rl"};
-
- private static final int[] WRITING_MODE_VALUES = new int[]
- {Constants.EN_LR_TB, Constants.EN_RL_TB, Constants.EN_TB_LR, Constants.EN_TB_RL};
-
- /** writing mode: lr-tb */
- public static final WritingMode LR_TB = new WritingMode(0);
- /** writing mode: rl-tb */
- public static final WritingMode RL_TB = new WritingMode(1);
- /** writing mode: tb-lr */
- public static final WritingMode TB_LR = new WritingMode(2);
- /** writing mode: tb-rl */
- public static final WritingMode TB_RL = new WritingMode(3);
-
- private static final WritingMode[] WRITING_MODES
- = new WritingMode[] {LR_TB, RL_TB, TB_LR, TB_RL};
-
- private WritingMode(int index) {
- super(WRITING_MODE_NAMES[index], WRITING_MODE_VALUES[index]);
- }
-
- /**
- * Assign writing mode traits from this trait to the specified
- * writing mode traits setter.
- * @param wms a writing mode traits setter
- * @param explicit true if writing mode property explicitly specified
- */
- public void assignWritingModeTraits(WritingModeTraitsSetter wms, boolean explicit) {
- Direction inlineProgressionDirection;
- Direction blockProgressionDirection;
- Direction columnProgressionDirection;
- Direction rowProgressionDirection;
- Direction shiftDirection;
- switch (getEnumValue()) {
- case Constants.EN_RL_TB:
- inlineProgressionDirection = Direction.RL;
- blockProgressionDirection = Direction.TB;
- columnProgressionDirection = Direction.RL;
- rowProgressionDirection = Direction.TB;
- shiftDirection = Direction.BT;
- break;
- case Constants.EN_TB_LR:
- inlineProgressionDirection = Direction.TB;
- blockProgressionDirection = Direction.LR;
- columnProgressionDirection = Direction.TB;
- rowProgressionDirection = Direction.LR;
- shiftDirection = Direction.RL;
- break;
- case Constants.EN_TB_RL:
- inlineProgressionDirection = Direction.TB;
- blockProgressionDirection = Direction.RL;
- columnProgressionDirection = Direction.TB;
- rowProgressionDirection = Direction.RL;
- shiftDirection = Direction.LR;
- break;
- case Constants.EN_LR_TB:
- default:
- inlineProgressionDirection = Direction.LR;
- blockProgressionDirection = Direction.TB;
- columnProgressionDirection = Direction.LR;
- rowProgressionDirection = Direction.TB;
- shiftDirection = Direction.BT;
- break;
- }
- wms.setInlineProgressionDirection(inlineProgressionDirection);
- wms.setBlockProgressionDirection(blockProgressionDirection);
- wms.setColumnProgressionDirection(columnProgressionDirection);
- wms.setRowProgressionDirection(rowProgressionDirection);
- wms.setShiftDirection(shiftDirection);
- wms.setWritingMode(this, explicit);
- }
-
- /**
- * Determine if WM is horizontal or not.
- * @return true if horizontal
- */
- public boolean isHorizontal() {
- switch (getEnumValue()) {
- case Constants.EN_LR_TB:
- case Constants.EN_RL_TB:
- return true;
- case Constants.EN_TB_LR:
- case Constants.EN_TB_RL:
- return false;
- default:
- assert false;
- return true;
- }
- }
-
- /**
- * Determine if WM is vertical or not.
- * @return true if vertical
- */
- public boolean isVertical() {
- return !isHorizontal();
- }
-
- /**
- * Returns the enumeration/singleton object based on its name.
- * @param name the name of the enumeration value
- * @return the enumeration object
- */
- public static WritingMode valueOf(String name) {
- for (WritingMode writingMode : WRITING_MODES) {
- if (writingMode.getName().equalsIgnoreCase(name)) {
- return writingMode;
- }
- }
- throw new IllegalArgumentException("Illegal writing mode: " + name);
- }
-
- /**
- * Returns the enumeration/singleton object based on its name.
- * @param enumValue the enumeration value
- * @return the enumeration object
- */
- public static WritingMode valueOf(int enumValue) {
- for (WritingMode writingMode : WRITING_MODES) {
- if (writingMode.getEnumValue() == enumValue) {
- return writingMode;
- }
- }
- throw new IllegalArgumentException("Illegal writing mode: " + enumValue);
- }
-
- private Object readResolve() throws ObjectStreamException {
- return valueOf(getName());
- }
-
- /** {@inheritDoc} */
- public String toString() {
- return getName();
- }
-
- }
|