You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PCLFontReaderFactory.java 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /* $Id$ */
  18. package org.apache.fop.render.pcl.fonts;
  19. import java.io.IOException;
  20. import org.apache.fop.fonts.CIDFontType;
  21. import org.apache.fop.fonts.CustomFont;
  22. import org.apache.fop.fonts.FontType;
  23. import org.apache.fop.fonts.MultiByteFont;
  24. import org.apache.fop.fonts.Typeface;
  25. import org.apache.fop.render.java2d.CustomFontMetricsMapper;
  26. import org.apache.fop.render.pcl.fonts.truetype.PCLTTFFontReader;
  27. public final class PCLFontReaderFactory {
  28. private PCLByteWriterUtil pclByteWriter;
  29. private PCLFontReaderFactory(PCLByteWriterUtil pclByteWriter) {
  30. this.pclByteWriter = pclByteWriter;
  31. }
  32. public static PCLFontReaderFactory getInstance(PCLByteWriterUtil pclByteWriter) {
  33. return new PCLFontReaderFactory(pclByteWriter);
  34. }
  35. public PCLFontReader createInstance(Typeface font) throws IOException {
  36. if (font.getFontType() == FontType.TRUETYPE || isCIDType2(font)) {
  37. return new PCLTTFFontReader(font, pclByteWriter);
  38. }
  39. // else if (font instanceof MultiByteFont && ((MultiByteFont) font).isOTFFile()) {
  40. // Placeholder for future Type 1 / OTF Soft font implementations e.g.
  41. // return new PCLOTFFontReader(font, pclByteWriter);
  42. // }
  43. return null;
  44. }
  45. private boolean isCIDType2(Typeface font) {
  46. CustomFontMetricsMapper fontMetrics = (CustomFontMetricsMapper) font;
  47. CustomFont customFont = (CustomFont) fontMetrics.getRealFont();
  48. if (customFont instanceof MultiByteFont) {
  49. return ((MultiByteFont) customFont).getCIDType() == CIDFontType.CIDTYPE2;
  50. }
  51. return false;
  52. }
  53. }