/*
 * Copyright (c) 2015 Diona Ltd.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of Diona
 * ("Confidential Information"). You shall not disclose such Confidential Information
 * and shall use it only in accordance with the terms of the license agreement you
 * entered into with Diona.
 */
package org.odk.collect.android.views;

import android.text.TextPaint;
import android.text.style.MetricAffectingSpan;

/**
 * A span adjuster that raises the span to the top of the line.
 */
public class SuperscriptSpanAdjuster extends MetricAffectingSpan {

  private static final double DEFAULT_RATIO = 0.2;
  private double ratio = DEFAULT_RATIO;

  /**
   * Default constructor that uses the #DEFAULT_RATIO.
   */
  public SuperscriptSpanAdjuster() {
  }

  @Override
  public void updateDrawState(TextPaint paint) {
    paint.baselineShift += (int) (paint.ascent() * ratio);
  }

  @Override
  public void updateMeasureState(TextPaint paint) {
    paint.baselineShift += (int) (paint.ascent() * ratio);
  }
}
